Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2005

Tip: Looking for answers? Try searching our database.

isErrorPage is not working in Tomcat 5.5 !

Thread view: 
rampaadh@gmail.com - 27 Jul 2005 16:18 GMT
Hi,

I have Tomcat 5.5 and i am having a jsp page which throws
a null pointer exception deliberately. I have defined a jsp error
handler
page, which is shown below,

ErrorHandler.jsp
================

<%@ page isErrorPage="true" %>
<%@ page session="true" %>
<html>
<body>
<b>Unable to process your request. </b>
<br/>Reason : <b><%=exception.toString()%></b>
Please try again.!
</body>
</html>

And in the first jsp page, I have given the errorPage as,

MyTemp.jsp
==========
<%@ page errorPage="ErrorHandler.jsp" %>
<html>
<body>
<%
    String s = null;
    s.indexOf("0");  // throw null pointer exception explicitly.
%>
</body>
</html>

When i access the MyTemp.jsp page,it is not forwarded to the error
handler jsp.
Instead,

"The page cannot be displayed " page with "HTTP 500 - Internal server
error " is displayed..

I don't know why the control is not going to the errorhandler page.

I searched for any configuration in tomcat so that all the exception
are not handled by the default tomcat error handler page.

But no luck..

One thing is , if i remove errorPage in Mytemp.jsp, tomcat displays the
exception stack in the browser itself..

Any help would solve my problem..

-pk
Alexey Efimov - 27 Jul 2005 16:37 GMT
Hi,

Did you have in your web.xml error-page definition for this JSP?
rampaadh@gmail.com - 28 Jul 2005 06:03 GMT
No,

I did not have any error-page definition in my web.xml

-pk.
Alexey Efimov - 28 Jul 2005 09:38 GMT
You must "setup" you error page correctly, for exaple:
http://java.sun.com/developer/EJTechTips/2003/tt0114.html
rampaadh@gmail.com - 28 Jul 2005 12:26 GMT
No luck...

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

in the web.xml and restarted the tomcat server..

and this is the ErrorHandler.jsp

<%@ page isErrorPage="true" %>
<%@ page session="true" %>
<html>
<body>
<b>Unable to process your request. </b>
<br/>Reason : <b><%=exception.getMessage()%></b>
Please try again.!
</body>
</html>

this is the test page:

<%@ page errorPage="ErrorHandler.jsp" %>
<html>
<body>
<%
    String s = null;
    s.indexOf("0");
%>
</body>
</html>

Still i am getting 500 internal server error.
Seems tomcat 5.5 is not forwarding to the ErrorHandler.jsp page...

I have tried all the options with error page tag in web.xml, but
nothing
is working as expected :(

Very disappointing....

-pk.
rampaadh@gmail.com - 28 Jul 2005 12:35 GMT
This is the ErrorHandler_jsp.java which is created by Tomcat:

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class ErrorHandler_jsp extends
org.apache.jasper.runtime.HttpJspBase
   implements org.apache.jasper.runtime.JspSourceDependent {

 private static java.util.Vector _jspx_dependants;

 public java.util.List getDependants() {
   return _jspx_dependants;
 }

 public void _jspService(HttpServletRequest request,
HttpServletResponse response)
       throws java.io.IOException, ServletException {

   JspFactory _jspxFactory = null;
   PageContext pageContext = null;
   HttpSession session = null;
   Throwable exception =
org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request);
   if (exception != null) {
     response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
   }
   ServletContext application = null;
   ServletConfig config = null;
   JspWriter out = null;
   Object page = this;
   JspWriter _jspx_out = null;
   PageContext _jspx_page_context = null;

   try {
     _jspxFactory = JspFactory.getDefaultFactory();
     response.setContentType("text/html");
     pageContext = _jspxFactory.getPageContext(this, request,
response,
                 null, true, 8192, true);
     _jspx_page_context = pageContext;
     application = pageContext.getServletContext();
     config = pageContext.getServletConfig();
     session = pageContext.getSession();
     out = pageContext.getOut();
     _jspx_out = out;

     out.write("\r\n");
     out.write("\r\n");
     out.write("<html>\r\n");
     out.write("<body>\r\n");
     out.write("<b>Unable to process your request. </b>\r\n");
     out.write("<br/>Reason : <b>");
     out.print(exception.getClass().getName());
     out.write("</b>\r\n");
     out.write("Please try again.!\r\n");
     out.write("</body>\r\n");
     out.write("</html>");
   } catch (Throwable t) {
     if (!(t instanceof SkipPageException)){
       out = _jspx_out;
       if (out != null && out.getBufferSize() != 0)
         out.clearBuffer();
       if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
     }
   } finally {
     if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context);
   }
 }
}

I don't know why

   Throwable exception =
org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request);
   if (exception != null) {
     response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
   }

is set ??

That may be the cause for putting the internal server error message..


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.