• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error handling servlet?

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While handling business exceptions programatically using a RequestDispatcher, which of the following attributes would you set in the request?
(Enthuware mock)

1. javax.servlet.error.status_code
2. javax.servlet.error.exception_type
3. javax.servlet.error.message
4. javax.servlet.error.exception

5. javax.servlet.error.servlet.

The correct options are in bold. Can anybody please give me an example of forwrding a request to the error handing servlet by request.getRequestDispatcher()??

The explanation given by the Enthuware is:--


An error handler servlet should have access to 4 attributes: javax.servlet.error.status_code, javax.servlet.error.exception, javax.servlet.error.servlet_name, and javax.servlet.error.request_uri.

So, if you are forwarding the request to an error handling servlet manualy using RequestDispatcher, you should set the above attributes in the request before forwarding the request to the servlet.

javax.servlet.error.exception_type and javax.servlet.error.message are basically redundant because these can be derived from the javax.servlet.error.exception attribute which contains the exception object



Thanks in advance
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is just simple. Suppose I have some file handling code in my servlet page. Now if there is some problem in the file handling, then I want to log the user out and then get him/her to the usual exception page, then I have two options, either I use this type of code



Now the respective error page defined in the web.xml file will be called. But if I want to show a different error page than declared in the web.xml, then I'll just forward the request in the catch block



The request attributes are just to make sure that any normal error page can be displayed. Since these are the attributes that are automatically set by the servlet container in the first example, so you should set them in the second case to maintain consistency. But you are not forced to do this. This is just a convention. I can create an error page which is not dependent on these attributes and then I'll not need to set these attributes. This is why the question is like this-

which of the following attributes would you set in the request?

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ankit, I really appreciate your affort to make me understand the concept.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well it was my pleasure to help you. And this is what programming is all about - "Conceptual Clarity". We can't go on memorizing everything. If one knows the concept, then sky is the limit for him/her...
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right Budy, That's why I am trying to achieve same
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya that's right buddy
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic