Juan Diego
Juan Diego

Reputation: 863

what's the right technique to redirect an Exception from a Servlet to a default error JSP?

I need to have a default error JSP page which is shown when an exception is thrown by the servlet, and that page will show the stacktrace..

How do I do that?? is there a right technique (provided by the API) or I have to do it manually?? I mean, sending the exception thrown as an attribute and then dealing with it by myself??

Thanks

Upvotes: 1

Views: 477

Answers (1)

Jonathan Holloway
Jonathan Holloway

Reputation: 63734

You can configure the exception type and the JSP page to handle in web.xml, e.g:

<error-page>
       <exception-type>UnhandledException</exception-type>
       <location>UnhandledException.jsp</location>
</error-page>

There's an Oracle article here on the subject:

http://www.oracle.com/technology/sample_code/tech/java/codesnippet/servlets/HandlingServletExceptions/HandlingServletExceptions.html

Upvotes: 3

Related Questions