"Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY). 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. The container clears the buffer and sets the Location header, preserving cookies and other headers. "
Remember setStatus() is used to set a header when there is NO ERROR.
sendError() in HttpServletResponse is defined as follows
public void sendError(int sc, java.lang.String msg) throws java.io.IOException
public void sendError(int sc) throws java.io.IOException
Both these methods say this
"If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to. "
SO Finally what j2eecertificate.com says is RIGHT.
Neither setStatus() nor sendError() are declared to throw an IllegalStateException.
setStatus() is NOT declared to throw ANY exception.(Just sets a header)
sendError() is declared to throw an IOException, But it can also throw an IleegalStateException if the response has already been commited before calling this method.
setStatus() sets a header value.
sendError() sends a FINAL response to the client.
5 More days to go.(For your exam that is) Isn't it? All the best in your EXAM CRAM.
Joined: Apr 14, 2005
Thanks a lot chowdary for ur quick replies.
Wow, u remembered my exam date(which I wrote about few days ago).
Actually in the last minute, I had to prepone my exam date. I'm writing my exam tomorrow, but i'm not sure if I'm ready yet.
so, little bit nervous(u know how valuable last few days are, and i'm missing those last minute revisions of what I thought I should read before the exam).
Joined: Aug 16, 2004
Don't worry. You'll do WELL.
Which part of the planet are you on?
If you are in the US, better go to bed. It's 1.50 AM Eastern Time.