InfoCenter Home >
4: Developing applications >
4.2: Building Web applications >
4.2.1: Developing servlets >
4.2.1.3: Servlet content, examples, and samples >
4.2.1.3.5: Enhancing servlet error reporting

4.2.1.3.5: Enhancing servlet error reporting

A servlet can report errors by:

  • Calling the ServletResponse.sendError method
  • Throwing an uncaught exception within its service method

The enhanced servlet error reporting function in IBM WebSphere Application Server provides an easier way to implement error reporting. The error page (a JSP file or servlet) is configured for the application and used by all of the servlets in that application. The new mechanism handles caught and uncaught errors.

To return the error page to the client, the servlet engine:

  1. Gets the ServletContext.RequestDispatcher for the URI configured for the application error path.
  2. Creates an instance of the error bean (type com.ibm.websphere.servlet.errorServletErrorReport). The bean scope is request, so that the target servlet (the servlet that encountered the error) can access the detailed error information.

For the Application Server, the ServletResponse.sendError() method has been overriden to provide the functionality previously described. The overriden method is shown below:

public void sendError(int statusCode, String message){
ServletException e = new ServletErrorReport(statusCode, message);
request.setAttribute(ServletErrorReport.ATTRIBUTE_NAME, e);
servletContext.getRequestDispatcher(getErrorPath()).forward(request, response);
}

Go to previous article: Servlet filtering with servlet chains Go to next article: Public methods of the ServletErrorReport class

 

 
Go to previous article: Servlet filtering with servlet chains Go to next article: Public methods of the ServletErrorReport class