Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define general/fall-back error page in web.xml

My Java web app currently maps certain error codes to an error servlet (spring web flow, actually, but that should be besides the point), by doing this in web.xml:

<error-page>
    <error-code>500</error-code>
    <location>/spring/error?error=500</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/spring/error?error=404</location>
</error-page>

However, in certain cases the server will still crash and give a stack trace dump of some exceptions to the user. (Running on IBM WebSphere btw). My question then is; is it possible to define a fall-back error page that will be used if all other errors don't match? So that we're guaranteed not to end up with a stack trace under any circumstance.

like image 945
Rune Aamodt Avatar asked Feb 18 '11 13:02

Rune Aamodt


People also ask

How to handle syntax errors in XML code?

The syntax error is identified by the parser. When it is been identified it generates XML Exception with the certain information which is given below: To handle the errors efficiently processing steps should be taken with the parser statement and special register as well. XML_CODE has numeric exception codes.

What is error page tag in WebLogic?

Error page tag: This tag is used to specify the error occurred in the while weblogic server is responding ti a HTTP request, returns an HTML page that displays either the HTTP error code. In the above example error-page tag specify the error code as 105 and location describes the location of the jsp page.

How to handle errors in your own error handling page?

In your own error handling page, you can hide the technical information by showing only readable message to the user. For example, here’s the HTML code of the Error404.jsp page: You can add other <error-page> elements to handle other error codes. For example, the following XML snippet declares the page that handles the HTTP 500 error:

How do I create a custom error page in WebSphere Application Server?

If the request is handled by a Web application running in WebSphere Application Server, and an error occurs, use the error-page option in web.xml (or web_merged.xml if it exists) to specify a customized error page. For more details, see the Information Center topic Web.xml.


1 Answers

Use the following:

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

See http://www.oracle.com/technology/sample_code/tech/java/codesnippet/servlets/HandlingServletExceptions/HandlingServletExceptions.html for more info.

like image 68
Peter Hulsen Avatar answered Sep 23 '22 00:09

Peter Hulsen