如何在Struts 2中找不到操作时处理404错误

时间:2014-04-05 11:06:28

标签: error-handling configuration struts2 http-status-code-404 action-mapping

在Struts2中,如果找不到操作,我想重定向到404.jsp页面 我在web.xml文件中添加了错误代码,如下所示。

<error-page>
    <error-code>403</error-code>
    <location>/403.jsp</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/404.jsp</location>
</error-page>

它呈现404.jsp页面内容,但在下面的日志中出现错误。 如何删除以下错误

2014-04-07 14:07:46,706  WARN (org.apache.struts2.dispatcher.Dispatcher:64) - Could not find action or result: /struts2-test/home11
There is no Action mapped for namespace [/] and action name [home11] associated with context path [/struts2-test]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
    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:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:1)

当应用程序配置为在struts.devMode中运行时,如果在呈现JSP页面时在运行时配置中未找到任何操作,则Struts 2框架会生成警告。它可以帮助开发人员解决Struts标记中操作的不适当映射。但是,动作映射并不总是静态推断,而是在运行时。因此,标记应该能够从值栈中的属性中找到映射。但struts标记仅在从错误页面重定向时不可用的操作上下文中执行。确保在重定向到Struts操作时,您具有映射到Struts操作的正确URL。