This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display Error Page in JSP

 
Devavrat Bagayat
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I want to display an Error Page, whenever a runtime exception occurs in the JSP.
I dont want to use -
<% page language="java" errorPage="URL"%>
But it should be done in the catch block. Something like response.sendRedirect(URL) used in servlets.
So how can it be done, if it is possible.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't explain why you'd rather not use the standard mechanism (highly recommened), but if you want to "roll your own" I'd:
1) Wrap the entire page in a try block
2) Create a catch clause that catches all exceptions
3) place the exception as an attribute in the request
4) forward (not redirect) to your error page
5) In your error page retrieve the exception from the request
hth,
bear
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use the error page attributes in the deployment descriptor for your web app.
Rgds
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic