*
The moose likes JSP and the fly likes Servlet exception not being forwarded to error page jsp defined in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Servlet exception not being forwarded to error page jsp defined in web.xml" Watch "Servlet exception not being forwarded to error page jsp defined in web.xml" New topic
Author

Servlet exception not being forwarded to error page jsp defined in web.xml

Clishta Karen
Greenhorn

Joined: Mar 16, 2004
Posts: 4
Hi,
I am trying to get my servlet's exception forwarded to error page defined in the web.xml.
In web.xml I have,
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/errorPage1.jsp</location>
</error-page>
And in my servlet, I am throwing ServletException.
As per the Servlet 2.3 specs, the exception should be forwarded to the error page.
The errorPage1.jsp has the following directive -
<%@ page language="java" isErrorPage="true" %>
But, when my servlet throws error, I just see a "Page Not Found" on my browser.
In the tomcat cache, I see the erroPage1.jsp converted into a servlet and compiled. This means that it is being requested, but the browser, instead of showing the contents of the errorPage1.jsp, just shows "Page Not Found"
Is there something I missed ?
ChandraMouli Vidiyala
Greenhorn

Joined: Dec 19, 2002
Posts: 12
Hi Clishta,
Just check, whether the path of the jsp in the application, and path mapping in xml are same or not.
Also, when the error jsp is thrown by the container title of the page is defaulted to "HTTP 404 Page Not Found". But the contents of the page should be the same as the jsp contents.
-Mouli.
Clishta Karen
Greenhorn

Joined: Mar 16, 2004
Posts: 4
Hi Chandra,
Thanks for the reply. The path to the jsp is correct and the application server even finds the jsp because I see it converted to servlet and then compiled.
This translation and compilation should occur only at the first request since I do not have any pre-compiling option checked.
So, I assume that the app server could see the jsp. I do not understand why it shows "Page not found - 404" instead of the contets of the jsp.
-Clishta
Karthik Prabu
Ranch Hand

Joined: Dec 27, 2002
Posts: 48
Hi Clishta
Change the entry in web.xml as instead of /errorPage1.jsp
Karthik
Clishta Karen
Greenhorn

Joined: Mar 16, 2004
Posts: 4
Hi Karthik,
Thanks for the reply.
But as per the web.xml DTD description, "error-location" has to start with a "/". If I just use "errorPage1.jsp", while starting tomcat, I see the following error -
Caused by: java.lang.IllegalArgumentException: Error page location http://devlap:8080/TestError/errorPage1.jsp must start with a /
at org.apache.catalina.core.StandardContext.addErrorPage(StandardContext
.java:1444)
It does not even take a complete URL and accepts the value provided in the "error-location", only if it starts with "/".
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet exception not being forwarded to error page jsp defined in web.xml
 
Similar Threads
Declaring an error page
Problem configuring Error Page
Explicit exception-type in DD
servlet not forwarding exception to the error-page defined in web.xml
response.sendError & error-page