FileDocCategorySizeDatePackage
ErrorGen.javaAPI DocExample1891Wed Feb 11 13:38:14 GMT 2004com.jspservletcookbook

ErrorGen

public class ErrorGen extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


    doPost(request,response);
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

 
 //check the servlet exception       
Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
String servletName = (String) request.getAttribute("javax.servlet.error.servlet_name");
   if (servletName == null)
       servletName = "Unknown";
   
String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
   if (requestUri == null)
       requestUri = "Unknown";

    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Error page</title>");  
    out.println("</head>");
    out.println("<body>");
    if (throwable == null){
      out.println("<h2>The error information is not available</h2>");
      out.println("Please return to the <a href=\"" + 
        response.encodeURL("http://localhost:8080/home") + "\">home page</a>");
   } else{
          out.println("<h2>Here is the error information</h2>");
 
  out.println(
      "The servlet name associated with throwing the exception: "+ 
        servletName + "<br><br>");
  out.println("The type of exception: " + 
       throwable.getClass().getName() + "<br><br>");
  out.println("The request URI: " + requestUri + "<br><br>");
  out.println("The exception message: " + throwable.getMessage());
   }
  out.println("</body>");
  out.println("</html>");
  out.close();