Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Clishta Karen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clishta
Change the entry in web.xml as instead of /errorPage1.jsp
Karthik
 
Clishta Karen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "/".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic