• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Ravinder S Edhan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we handle exception in JSP?

Here is one of the senario..

I have one 'test.jsp'. In that jsp I'm including another jsp('header.jsp') using <% include file ="" %>. In test.jsp ... there is a code for forwording the error to error.jsp i.e <%@ page errorPage="error.jsp"%>.

Now I'm forcefully throwing the exception in 'header'jsp. I want that a custom error messge should be displayed to the user via that error.jsp, instead of that I'm getting a stack trace on that header.jsp

Direct me how to display the custom message via error.jsp

Regards
Ravinder
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always let exceptions propogate out of the JSP pages (in other word, no catching on the pages, and no error page declarations), and specify an error handler servlet in the web.xml file.

That servlet looks over the error and decides what to do, usually forwarding to an "error JSP" that displays a user-facing message and options for proceeeding.
 
Ravinder S Edhan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had tried the either way also as you do. But then also the error.jsp page is not getting displayed.


Ravinder
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then something in your setup is not correct.
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravinder , Make sure that in the Error.jsp file , You have declared it as isErrorPage="true" and you are using the exception object to print the custom error message to the user.

Yogendra Joshi.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!