严重: action: null
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/action-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/action-servlet.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:356)
at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:297)
at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:227)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/action-servlet.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 41 more
2012-3-25 11:53:05 org.apache.catalina.core.ApplicationContext log
信息: Marking servlet action as unavailable
2012-3-25 11:53:05 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /TestSS threw load() exception
javax.servlet.UnavailableException
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:880)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
出现上面错误可以产看一下Struts.xml插件那是否配错了
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property value="/WEB-INF/applicationContext.xml" property="
contextConfigLocation
"/>注意第一个字母是小写,若果大写就会出现上述情况了
</plug-in>
使用spring
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
IDISK idisk = (IDISK)context.getBean("disk");//根据配置文件的内容实例化对象并返回
配置文件
scope="prototype"取消单态,延迟加载只针对单态的bean适用,非单态的bean本来就是“延迟加载”
<bean id="dbreader" class="reader.DBReader" scope="prototype">
<!-- 构造方法注入
<constructor-arg index="0" type="java.lang.String">
<value>sfk</value>
</constructor-arg>
<constructor-arg index="1" type="java.lang.String">
<value>sfk</value>
</constructor-arg>
-->
<property name="driverClassname">
<value>sun.jdbc.odbc.JdbcOdbcDriver</value><!-- 属性注入 -->
</property>
<property name="url">
<value>url</value>
</property>
<property name="username">
<value>username</value>
</property>
<property name="password">
<value>password</value>
</property>
</bean>
核心代码
Session session = util.HibernateSessionFactory.getSession();
School school = (School)session.get(School.class,
02
);
System.out.println(school.getSname());
System.out.println(school.getHeader().getHname());
school.getHeader().setHname("王强");
Transaction transaction = session.beginTransaction();
session.update(school);
session.delete(school);
transaction.commit();
util.HibernateSessionFactory.closeSession();
配置文件
<class name="po.School" table="school">
<id column="SID" name="sid">
<generator class="assigned"/>
</id>
<property column="SNAME" generated="never" lazy="false" name="sname"/>
<one-to-one cascade="all" class="po.Header" name="header"/>
</class>
<class name="po.Header" table="Header">
<id name="hid" column="HID">
<generator class="increment" />
</id>
<property name="sid" column="SID"/>
<property name="hname" column="HNAME"/>
</class>
hibernate 与数据库的耦合性较低。
在一对一关系中要注意找出谁是主动方,在上面的例子中School是主动方,在主动方里面添加被动方的属性,上述例子添加了Header属性,然后到配置文件中注册。使用的时<one-to-one、>
如果在使用ps 3D->从图层新建形状->...出现下边错误
1、DispatchAction
当一个action要处理两个操作时,如以下情况
<html:form
action="/buy.do?method=add"
method="post">
请您选择书本 : <html:text property="book"/><html:errors property="book"/><br/>
<html:submit value="添加到购物车"/>
</html:form>
<hr>
以下是您选的熟本<br>
<logic:present name="cart">
<logic:iterate id="book" name="cart">
<bean:write name="book"/><html:link
action="/buy.do?method=delete"
paramId="BOOK" paramName="book">删除</html:link><br>
</logic:iterate>
</logic:present>
我们都是用buy这个action来处理的,action继承了DispatchAction,为了让页面识别action中的add()方法和delete()方法,我们需要在struts.xml中配置<action parameter="method"></action>,这种方法耦合性高。需要页面识别action中的方法。
2、MappingDispatchAction
这种方法可以降低耦合性,指向多个结构不同的ActionForm,以上jsp可以如下
<html:form
action="/add.do"
method="post">
请您选择书本 : <html:text property="book"/><html:errors property="book"/><br/><html:submit value="添加到购物车"/>
</html:form>
<hr>
以下是您选的熟本<br>
<logic:present name="cart">
<logic:iterate id="book" name="cart">
<bean:write name="book"/><html:link
action="/delete.do"
paramId="BOOK" paramName="book">删除</html:link><br>
</logic:iterate>
</logic:present>
在struts.xml中设置如下<action path="/add"parameter="add"></action>
<action path="delete"parameter="delete"></action>
3、LookupDispatchAction
这种情况一般是同一个表单可以提交到多个不同的按钮,这种方法耦合性低,比较麻烦,需要用到资源文件。举例:jsp如下
<html:form action="/lr">
account : <html:text property="account"/><br/>
password : <html:text property="password"/><br/>
<html:submit
property="ope"
><bean:message key="info.tag.login"/></html:submit>
<html:submit
property="ope"
><bean:message key="info.tag.reg"/></html:submit>
</html:form>
我们在action中需要重写getKeyMethodMap()
protected Map getKeyMethodMap() {//用一个map保存资源文件和方法名的映射
// TODO Auto-generated method stub
Map map = new HashMap();
map.put("info.tag.login","
login
");
map.put("info.tag.reg","
reg
");
return map;
}
login 和 reg 用来选择方法。在struts.xml中需要作如下配置
<actionparameter="ope"></action>