My first idea was to try to solve this issue in struts.xml, but after some research I was directed to try to solve it in web.xml, as it is done in any Java Web project:
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- version="2.4">
- <display-name>Aplicacao web simples</display-name>
- <welcome-file-list>
- <welcome-file>/bemvindo.jsp</welcome-file>
- </welcome-file-list>
- <error-page>
- <error-code>404</error-code>
- <location>/erro.jsp</location>
- </error-page>
- </web-app>
That did not work. When a non existent page was accessed, the following exception was raised and the page was blank:
2010-12-08 14:50:43 Dispatcher [WARN] Could not find action or result
There is no Action mapped for namespace / and action name pan. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
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:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
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:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
After some more research, I was properly directed to the solution, and it really was in struts.xml. No configuration is necessary in web.xml. [1]
You just have to set a default action. So, when struts receives a request that doesn't match any action, the request will be sent to your custom error page. The struts.xml looks like this:
<default-action-ref name="pageNotFound" />
<action name="pageNotFound">
<result>/pageNotFound.jsp</result>
</action>
Links:
[1] http://struts.apache.org/2.0.14/docs/action-configuration.html
[2] http://wiki.metawerx.net/wiki/Web.xml.ErrorCode
[3] http://www.coderanch.com/t/428310/Struts/Interceptor-messes-up-action-class
[4] http://www.mkyong.com/struts2/there-is-no-action-mapped-for-namespace-and-action-name-youractionname/
No comments:
Post a Comment