jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Exception redirect to page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception redirect to page" Watch "Exception redirect to page" New topic

Exception redirect to page

Dan Parsons
Ranch Hand

Joined: May 30, 2007
Posts: 70
Sometimes I have Servlets in my Tomcat 4.1.27 container that display information and there might be times when an Exception happens. I like to have a redirect to show a user friendly error page. The below is how I have been doing it and was wondering if this is the proper way to do it where the error message goes to the Tomcat log file and the page redirects.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

It is not the proper way. Rather you should not catch the exception at all. Declare your error page(es) in the web.xml. The Servlet Specificatin spells all of this out in the error handling section.

[Asking smart questions] [About Bear] [Books by Bear]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
In the web.xml



Majid Al-Fifi
Ranch Hand

Joined: Aug 22, 2006
Posts: 45

In the error page you will not have "code that may cause the exception" rather you may have code that generate useful message to the user about what the problem was.



Kishore Nallamothu

Joined: Aug 28, 2006
Posts: 9


U said <error-page> in web.xml
my Quest. is where we write <error-page> tag i.e.in servlet tag or
servlet-mapping tag.

Thanks in Advance

Joined: May 21, 2007
Posts: 17
Does this mean if it generates an error/exception in the action/service class it will log the error and redirect to the error.jsp?
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

after multiple requests to correct your display name, I am now disabling your account.

If you would like to participate in this conversation, please do so with an account with a valid display name.

Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
Kishore there is no error tag in servlet or servlet-mapping tag. There is a separate tag called

<error-page> and the attributes of these are

I agree. Here's the link: http://aspose.com/file-tools
subject: Exception redirect to page
It's not a secret anymore!