Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect the request

 
Amandeep Singh
Ranch Hand
Posts: 850
  • 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.
 
Vishal Chugh
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
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think answer would be A.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 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
 
Archana Venkatesh
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
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2339
90
Android Chrome Eclipse IDE
  • 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