File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes response.setStatus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "response.setStatus" Watch "response.setStatus" New topic


Yogesh Hingmire
Ranch Hand

Joined: Dec 06, 2005
Posts: 61
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

could you please let me know on the same.

Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 549

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 ?

SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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.

[My Blog]
All roads lead to JavaRanch
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
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


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

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


hth and also please anwer my question !

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

sendError will trigger it.
(please start new threads when asking your own questions)
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
(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.

I agree. Here's the link:
subject: response.setStatus
It's not a secret anymore!