开发者

Struts 2 + error pages + configuration

I'm trying to configure a global error page for my struts 2 project. So far i've done the following:

<global-results>
  <result name="Exception">/jsp/common/errorPage.jsp</result&g开发者_JS百科t;
</global-results>
<global-exception-mappings>
 <exception-mapping exception="java.lang.Throwable" result="Exception" />
</global-exception-mappings>

And in my web.xml:

<error-page>
  <exception-type>java.lang.Throwable</exception-type>
  <location>/jsp/common/errorPage.jsp</location>
</error-page>
<error-page>
 <error-code>404</error-code>
 <location>/jsp/common/errorPage.jsp</location>
</error-page>

Struts handles all /* requests. When I'm deliberately trying to go to an unmapped location, I'm getting the error stack trace stating

There is no Action mapped for namespace / and action name checkErrorPage. - [unknown location]

When I'm throwing an error in an mapped action, I'm getting the stack trace again instead of the error page. I'm rethrowing the error as suggested in other solutions on the web, but it's still not redirecting to the error page.

What am I doing wrong?

Thanks


Your configuration works for me in a test project. Please indicate what version of Struts2 are you using. Also, if struts.devMode is set to true, then that would explain why your custom page isn't being used for the 404 responses. With dev mode on, Struts 2 will replace the 404 response with a built-in error page that tries to give you detailed information for debugging.

Note that your custom error page should still be used for exceptions thrown from your actions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜