• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setStatus(),sendError() & IllegalStateException

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I'm sorry for not trying out these and asking others questions.

in IBM site, i found that

These methods(setStatus() and sendError() ) throw an IllegalStateException if the response is already committed.


but j2eecertificate.com says
" setStatus(int sc) method is not declared to throw an IllegalStateException" where as sendError() can throw IllegalStateException.


which statement about setStatus() is correct?


Thanks
Suma
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Suma

IBM IS WRONG.(By what you said)

setStatus in the javadocs says

"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

OR

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.
 
suma sindu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

Suma
 
chowdary Thammineedi
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic