我们使用struts1-plugin将旧的Struts 1应用程序迁移到Struts 2来包装我们的操作。
这在某些操作中效果很好,但其他操作会抛出如下所示的错误:
java.lang.InstantiationException
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
java.lang.Class.newInstance(Class.java:374)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:158)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:189)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.resolveModel(ScopedModelDrivenInterceptor.java:106)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:136)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
de.dak.intranet.webtier.extranet.StartPageFilter.doFilter(StartPageFilter.java:74)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
de.dak.intranet.webtier.auth.LoginFilter.doFilter(LoginFilter.java:288)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
此操作的配置非常简单:
<package name="extranet" extends="struts1-default" namespace="/extranet">
<action name="acceptConditions" class="org.apache.struts2.s1.Struts1Action>
<param name="className">de.intranet.webtier.extranet.AcceptConditionsAction</param>
<interceptor-ref name="struts1Stack"/>
<result name="success">/servlet/index.jsp</result>
</action>
</package>
我尝试在动作中移除拦截器但是没有改变任何东西。 动作类看起来像这样(省略了实际逻辑):
public class AcceptConditionsAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}
我们的jsp模板中的链接使用s:action-tag正确构建,并且在单击链接时,同一站点上的另一个操作可以正常工作。但是,此操作会生成上面显示的堆栈跟踪,但我无法确定它来自何处或如何修复它。从未到达动作内部的断点,因此在实例化动作本身时必须发生错误。
我希望有人可以帮我弄清楚发生了什么。
编辑: 澄清的工作行动:
<package name="extranet" extends="struts1-default" namespace="/extranet">
<interceptors>
<interceptor name="pwdForm" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor>
<param name="className">de.intranet.webtier.extranet.PasswordForm</param>
<param name="name">pwdForm</param>
</interceptor>
</interceptors>
<action name="editPassword" class="org.apache.struts2.s1.Struts1Action">
<param name="className">de.intranet.webtier.extranet.EditPasswordAction</param>
<interceptor-ref name="pwdForm"/>
<interceptor-ref name="struts1Stack"/>
<result name="changePassword">/extranet/changePassword.jsp</result>
</action>
</package>
Java实现看起来像AcceptConditionsAction。只覆盖了执行方法,没有定义构造函数。
答案 0 :(得分:1)
struts1Stack
)提供的拦截器堆栈创建了几个需要表单的拦截器(即scopedModelDriven
,modelDriven
和其他一些拦截器。如果您不使用整个堆栈并且只添加操作所需的拦截器,则不再需要定义FormBean
。
答案 1 :(得分:0)
删除interceptor-ref&#34; strutsStack&#34;,添加&#34; staticParams&#34;会做的。 如下所示
<package name="extranet" extends="struts1-default" namespace="/extranet">
<action name="acceptConditions" class="org.apache.struts2.s1.Struts1Action>
<param name="className">de.intranet.webtier.extranet.AcceptConditionsAction</param>
<!--interceptor-ref name="struts1Stack"/-->
<interceptor-ref name="staticParams"/>
<result name="success">/servlet/index.jsp</result>
</action>
</package>