Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

isErrorPage is not working in Tomcat 5.5 !

40 views
Skip to first unread message

ramp...@gmail.com

unread,
Jul 27, 2005, 11:18:43 AM7/27/05
to
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

unread,
Jul 27, 2005, 11:37:30 AM7/27/05
to
Hi,

Did you have in your web.xml error-page definition for this JSP?

ramp...@gmail.com

unread,
Jul 28, 2005, 1:03:32 AM7/28/05
to
No,

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

-pk.

Alexey Efimov

unread,
Jul 28, 2005, 4:38:29 AM7/28/05
to
You must "setup" you error page correctly, for exaple:
http://java.sun.com/developer/EJTechTips/2003/tt0114.html

ramp...@gmail.com

unread,
Jul 28, 2005, 7:26:07 AM7/28/05
to
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.

ramp...@gmail.com

unread,
Jul 28, 2005, 7:35:37 AM7/28/05
to
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..

0 new messages