作了2個action,其中一個運行沒有問題,另外一個報錯,看下面的報錯信息,再看了看struts.xml,由於沒有給GetBooks這個action配置actionform,因此就致使報null。下面是有問題的struts.xml,其中主要的問題就是沒有給GetBooks這個action配置actionform,也就是沒有添加那個interceptor-ref name="integration",添加上就行了(這個form在應用的邏輯裏面,GetBooks是不須要form的,可是多是因爲struts2和struts1整合的時候要求每一個action都必須有form,因此我就隨便給GetBooks這個action配置了一個form,在GetBooks這個action裏面不使用那個form就好了)java
<?xml version="1.0" encoding="GBK" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.i18n.encoding" value="GBK"/> <constant name="struts.custom.i18n.resources" value="messageResource"/> <package name="lee" extends="struts1-default" namespace="/test"> <interceptors> <interceptor name="loginForm" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"> <param name="className">lee.LoginForm</param> <param name="name">loginForm</param> </interceptor> <interceptor-stack name="integration"> <interceptor-ref name="staticParams"/> <interceptor-ref name="loginForm"/> <interceptor-ref name="modelDriven"/> <interceptor-ref name="actionForm-reset"/> <interceptor-ref name="basicStack"/> <interceptor-ref name="actionForm-validation"/> <interceptor-ref name="workflow"/> </interceptor-stack> </interceptors> <action name="Login" class="org.apache.struts2.s1.Struts1Action"> <param name="className">lee.LoginAction</param> <result name="success">welcome.jsp</result> <result name="error">error.jsp</result> <interceptor-ref name="integration" /> </action> <action name="GetBooks" class="org.apache.struts2.s1.Struts1Action"> <param name="className">lee.GetBooksAction</param> <result name="login">login.jsp</result> <result name="success">showBook.jsp</result> </action> </package> </struts>
嚴重: Exception occurred during processing request: null
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:433)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:151)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:182)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:171)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.resolveModel(ScopedModelDrivenInterceptor.java:106)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:136)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:744)apache