This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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 ?
 
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
 
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 "/".
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic