isErrorPage is not working in Tomcat 5.5 !

R

rampaadh

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
 
R

rampaadh

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.
 
R

rampaadh

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..
 
Joined
May 8, 2009
Messages
1
Reaction score
0
Solved

Well, I know, it has been almost 4 years...but i faced just the same problem, and after a long time trying to figure it out, i would like to share it with others.

You updated your Tomcat to version 5.5, right? So that old jasper-runtime.jar and servlet.jar in your WEB-INF/lib need to be upgraded also. In my case I just removed them and everything went OK. Just that.
 
Joined
Jan 8, 2010
Messages
1
Reaction score
0
jsp error - java.lang.NullPointerException - SOLVED

I've been working on this problem ALL week and I just fixed it. I tried most of the things suggested in this thread, with no luck. Just now, I decided to try commenting the line "<%@ page isErrorPage="true" %>" out of my jsp, and it worked! My problem was that a generic error page was displaying instead of the error page that was supposed to be displayed based on the response code from HttpServletResponse, in this case a 403/Forbidden. Oh, and this is in Sun Webserver7, not Tomcat.

Thank goodness for this forum, for who knows when I would have figured it out and it needs to be finished a.s.a.p.

Best,
Sue
8)
 
Last edited:
Joined
Dec 30, 2010
Messages
2
Reaction score
0
Http 500 Internal Server Error

The main reason of 500 error is "<%@ page isErrorPage="true" %>" tag, this will work fine on mozilla but on IE tomcat you will face problem. So just do this "<%@ page isErrorPage="false" %>", now you will get same error on jsp as well as mozilla. Still i'm digging how we can solve this issue on IE with tomcat.
 
Joined
Dec 30, 2010
Messages
2
Reaction score
0
Http 500 Internal Server Error

The main reason of 500 error is "<%@ page isErrorPage="true" %>" tag, this will work fine on mozilla but on IE tomcat you will face problem. So just do this "<%@ page isErrorPage="false" %>", now you will get same error on jsp as well as mozilla. Still i'm digging how we can solve this issue on IE with tomcat.:trytofly:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top