开发者

Detect exceptions in JSP page via RequestDispatcher

I have a JSP page with an error page specified. I call the page from a servlet via:

RequestDispatcher rd = ctx.getRequestDispatcher( jspPage );
rd.include( req, res );

How can I detect if the jsp page forwarded to the error page or not? I want to handle exceptions differently but no exception is thrown. And unfortunately I can't modify the JSP page itself or the error pa开发者_StackOverflow中文版ge.

Edit:

I'm thinking something like this might work after the include() line, any thoughts?

Object errorServletName = req.getAttribute( "javax.servlet.error.servlet_name" );
if ( errorServletName != null ) 
{ there was an error in the JSP... }


Add to your web.xml file this:

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.html</location>
</error-page>

Assuming that you have stack trace printout or similar way of notifying the user about there problem they experienced on error.html page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜