permaculture playing cards
The moose likes JSP and the fly likes Display Error Page in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Display Error Page in JSP" Watch "Display Error Page in JSP" New topic
Author

Display Error Page in JSP

Devavrat Bagayat
Greenhorn

Joined: Jun 24, 2001
Posts: 25
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

Joined: Jan 10, 2002
Posts: 63350
    
  70

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
You could also use the error page attributes in the deployment descriptor for your web app.
Rgds
Sam


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display Error Page in JSP
 
jQuery in Action, 3rd edition