Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception redirect to page

 
Dan Parsons
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the web.xml


someErrorfullPage.jsp




Thanks,
 
Majid Al-Fifi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cmbhatt,

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.

regards,

Majid
 
Kumar N Krishna
Greenhorn
Posts: 10
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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
 
Vyas
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Vyas",
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.

Dave
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

<error-code>
<exception-type>
<location>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic