| Author |
Get user defined exception error message to error jsp page from servlet
|
shiva kumar g
Greenhorn
Joined: Jun 08, 2010
Posts: 6
|
|
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
Joined: Mar 14, 2010
Posts: 42
|
|
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.
|
SCJP 1.6,Preparing (Tryin to prepare) for scwcd
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
shiva kumar g
Greenhorn
Joined: Jun 08, 2010
Posts: 6
|
|
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
Joined: Apr 25, 2010
Posts: 503
|
|
|
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...
|
Regards, Prasad
SCJP 5 (93%)
|
 |
 |
|
|
subject: Get user defined exception error message to error jsp page from servlet
|
|
|