Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

response.setStatus

 
Yogesh Hingmire
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,

will a response.setStatus() result in activating the error handling mechanism.
i mean when we use this mehtod with status code as 4xx or 5 xx and i have the <error-page> in the web.xml for these codes ?

My guess is it wont activate the web.xml declared error page handling
mechanism.

could you please let me know on the same.

Thanks,
Yogesh
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you are right, setStatus(int statusCode) does not interact with the error page defined in the <error-page> tag in web.xml
This method does not trigger the container to generate an error page. It just sends the status code to the browser.

Can anyone confirm ?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's clearly written in the API for setStatus() :
If there is an error, and the caller wishes to invoke an error-page defined in the web application, the sendError method should be used instead.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
7. Instead of displaying the standard HTTP 404- NOT FOUND message for all bad requests to a web application, you want to display a customized page. Which of the following is the correct way to do this? (Select one)

a You have to check the servlet container documentation and change the default error message file.
b You have to change your servlets to redirect the responses to your customized error message file.
c You have to specify the mapping of the error-code (404) and the customized error page in web.xml.
d You cannot do it in a standard way.

Answer: c

Explanation

You can map error codes to error pages just as you map exception types to error pages. The following web.xml snippet maps 404 to
V



but i am not sure which method will trigger the custom html page -

setStatus(SC_NOT_FOUND);
OR
sendError(SC_NOT_FOUND);

hth and also please anwer my question !
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendError will trigger it.
(please start new threads when asking your own questions)
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(please start new threads when asking your own questions)


I think this is the job of the moderator to tell me.
My information / query was in context with the post above.

so...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic