Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Redirect the request

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can you redirect the request from a servlet to another resource if the servlet encounters an exception?

a. This cannot be done unless the exception is caught in the servlet.

This answer is wrong but it should be right, i don't know this answer is the wrong answer.

b. By specifying a mapping between exception class and the resource in web.xml.


c. This can be done only if the exception is a subclass of javax.servlet.ServletException.


d. This can be done even if the exact class of the exception is not known at compile time.
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think answer would be A,C .Is it? Could you please confirm?

Thanks
Vishal Chugh
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think answer would be A.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Amandeep Singh:
d. This can be done even if the exact class of the exception is not known at compile time.



Hi dude Amandeep Singh,

It seems to be correct
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Even I am not clear about the answers to this question. I think A and C are correct answers.
Is there a way to specify a mapping between exception class and resource in web.xml ??? ( as mentioned in the Option B )
I guess this can be done only for JSPs by configuring <error-page> tag. Can this be done for servlets too ???


Thanks,
Archana
 
Creator of Enthuware JWS+ V6
Posts: 3290
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there a way to specify a mapping between exception class and resource in web.xml ??? ( as mentioned in the Option B )
I guess this can be done only for JSPs by configuring <error-page> tag. Can this be done for servlets too ???


Yes, this also works for Servlets (have a look at the specs ans search for error handling).

Just create a Servlet yourself and throw a ServletException from it:
like:

and define an entry in your web.xml like:

You will be redirected to your error page as soon as your Servlet throws the ServletException.
Regards,
Frits
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!