Tomcat Error Pages list Display different error pages in tomcat setup Error Pages in tomcat

Setup error pages in tomcat

We can set up error pages for our applications running on tomcat server,so that when error or exception is thrown the user can get the appropriate message instead of the usual tomcat exception page which a user cant understand.The proper way to handle this issue is to have one`s own exception classes and throw them from the code and display error pages stating the possible causes for the error or exception and how to get rid of the same.Basically an error is a bug which is cannot be handeled from the source code such as linkage error or JVM crashes etc.An exception is a bug which our source code is liable to handle.Exceptions like file not found,sql exception etc. are checked exceptions which our code necessarily need to handle because of their possiblities of occurrences.Other exceptions which are run time exceptions need not be handled from our code as they are runtime and basically are logical errors such as division by zero,null pointer exception etc.But we can configure the error pages for errors and exceptions regardless of their nature in our tomcat application in the similar manner.We need to introduce a tag <error-pag> in our application`s web.xml file.In which we can specify error code and the location of the file to which the application must proceed if the error or exception has occurred.The snippet from the web.xml file is shown below :






The error-page tag is generally put in the last section of web.xml file,just below the welcome-file tag.Here we have put one error and an exception for demonstration.When we talk about errors we need to specify the error code in the <error-code> tag and the location of the html or jsp file which should be displayed when the error occurs.Likewise we have to cofigure for exceptions with the difference that instead of error in the error-code tag ,we have to write the fully qualified name of the exception class.For the checked exceptions however we need to throw our own exception derived from the class RuntimeException from the catch block of our code and configure the error page for our derived class inside the web.xml file.

Number of View :215314


  1. #1 written by admin October 14th, 2010 at 05:03

    error pages tomcat exception. how to set up error pages in tomcat apache tomcat error exceptions comming soon..set up error pages on tomcat server, RESTful error handling with Tomcat and Spring, Catching Error Code in Tomcat, Servlets forum

    RE Q
  2. #2 written by bhagwat June 2nd, 2011 at 23:16

    RE Q

Content Protected Using Blog Protector By: PcDrome.