|
Currently doing a web application, struts2 + spring + hibernate, server is tomcat. We want users in the IE address bar Luanqiao when all undefined URL that can be typed into the capture process, then go to a home-made 404 error handling page.
First, access to online information that can be added in web.xml so:
< Error-page>
< Error-code> 404 < / error-code>
< Location> /error/404.jsp < / location>
< / Error-page>
Thus, it is not found 404 error will go /error/404.jsp accept the deal.
But after testing, I found that the end of the URL .action struts2 framework will first be captured, not directly into web.xml configured handle page. Thus, if the appropriate action is not configured in struts.xml, an error is output in the tomcat:
Serious: Could not find action or result
There is no Action mapped for namespace / and action name ****** -. [Unknown location]
While the final configuration can be transferred to the web.xml processing page, but this blind at the command station output something very easy to program and debug management, so I have to find ways to deal with struts2 framework undefined action.
Access to online information, can be found in struts.xml, add a default package, then this default package, add a default action, so that the action turned 404 error handling page:
< Package name = "default" extends = "struts-default">
< Default-action-ref name = "notFound" />
< Action name = "notFound">
< Result> /error/404.jsp < / result>
< / Action>
< / Package>
The default package feature is that you do not define namespace attribute, so all undefined namespace will turn here. name = "default" is for ease of reading, in fact, is what the name can also be empty: name = "".
And then also in the other package has been defined also add the default action, turn to page 404 error handling. So that it can fully handle all the 404 errors. |
|
|
|