aspose file tools*
The moose likes Servlets and the fly likes Get user defined exception error message to error jsp page from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get user defined exception error message to error jsp page from servlet" Watch "Get user defined exception error message to error jsp page from servlet" New topic
Author

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

shiva kumar g
Greenhorn

Joined: Jun 08, 2010
Posts: 9
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: 45

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: 61752
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
shiva kumar g
Greenhorn

Joined: Jun 08, 2010
Posts: 9
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: 586
    
    3

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get user defined exception error message to error jsp page from servlet