This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes error page doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "error page doubt" Watch "error page doubt" New topic
Author

error page doubt

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Which of the following is a sensible way of sending an error page
to the client in case of a business exception that extends from java.lang.Exception?

a)Catch the exception and use RequestDispatcher to forward the request to the error page.
b)Don't catch the exception and define the 'exception to error-page' mapping in web.xml
(You can use this approach only if the business exception extends from RuntimeException.)

c)Catch the exception, wrap it into ServletException and define the 'business exception to error-page' mapping in web.xml


d)Catch the exception, wrap it into ServletException, and define the 'ServletException to error-page' mapping in web.xml

d)Don't do anything, the servlet container will automatically send a default error page.
(This will happen only if you call response.sendError(...) method.)

Ans Given As : a and c
I think the ans should be a) and b)

Also the following statement is incorrect:

Don't catch the exception and define the 'exception to error-page' mapping in web.xml
(You can use this approach only if the business exception extends from RuntimeException.)


I have seen the code
<error-page>
<exception-type>java.lang.Throwable </exception-type>
<location>/error.jsp</location>
</error-page>
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Javaranchers,
Still No Reply !!!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Sandeep Vaid:
Javaranchers,
Still No Reply !!!


Patience Is A Virtue


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Asif
Greenhorn

Joined: Mar 29, 2008
Posts: 9
DD is d bestest way ..
i guess d ans shd only b b) ..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41087
    
  43
Sandeep, please QuoteYourSources

"Listener event", on your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error page doubt
 
Similar Threads
Doubt on send Error
don't understand this question
Wrapping a business exception in ServletException in doPost()
sensible way of sending error page to the client
Q: Appropriate Exception Handling in a servlet