Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get user defined exception error message to error jsp page from servlet

 
shiva kumar g
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My requirement is to throw user defined exception from servlet with some error code/message. As i have configured this user defined exception type and error jsp in web.xml as

Coming to user defined exception class i have defined as
From my servlet if there is any exception i am throwing MyownException("E001") etc but i am not getting the thrown error message in the jsp.
In error page jsp giving it as
From servlet i am thowing exception as
But when there is an exception the error page is not getting executed and control is going further from the above try catch block and executing the rest code too.
Help me if there is any issue. Also guide me if i am doing anything wrong.
 
Harsha Ka
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You are throwing your custom exception and also catching it.So the flow is not going to the JSP. Yow will either need to remove the try-catch block or better, just add the exception object in the request scope and forward it to the JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception flow should not be going to the JSP nor caught in the servlet. Configure an error handler in the deployment descriptor, log the error, then forward to a JSP that displays a message to the user. The user should never see the exception stack trace, just a customer-appropriate message.
 
shiva kumar g
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,


Thanks for your reply.

My issue has been resolved as i am throwing the custom exception from servlet and keeping the same exception in a request scope as

In error jsp page type casting to custom exception and displaying the nice error message on to the error page

Hope i am doing right.
Once again thanks for the reply.
 
Prasad Krishnegowda
Ranch Hand
Posts: 670
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you are not doing right.. Writing java code in JSP's is very bad, it is been discredited for a decade now. Time to move on to JSTL...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic