How do I configure my Application Server to show a different Error page upon an exception from a JSP or Servlet?

Garth Somerville

There should be one answer to this question that works for all 2.2 compliant servlet containers. The answer is to edit the web.xml deployment descriptor for your web app and add an error-page tag. The error-page tag tells the container the location of a page to return when an exception or error occurs. You can use the same mechanism to return customized error pages based either on a specific exception that is thrown, or based on the HTTP status code that is returned. The tag looks like this:

<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>myPage.html</location>
</error-page>
Or

<error-page>
<error-code>500</error-code>
<location>myPage.html</location>
</error-page>

[RC - If you know of a servlet container that does things differently (i.e. prior to Servlet 2.2), please submit as feedback, I am hoping to have answers for a few AppServers.]
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact