• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendError

 
Shubh Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q:
The sendError method defined in the HttpServlet class is equivalent to invoking the setStatus method with the following parameter. Select the one correct answer.
1. SC_OK
2. SC_MOVED_TEMPORARILY
3. SC_NOT_FOUND
4. SC_INTERNAL_SERVER_ERROR
5. ESC_BAD_REQUEST
why should the answer for the above question be 3. and not 4?
Thanks in advance.
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm not mistaken, that question is actually incorrect as there is no sendError or setStatus in HttpServlet class, they are in HttpServletResponse class.
Other than that, I am not sure about the answer. Had a look at the API but could not figure out.
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I got it now. If you read the HttpServletResponse Interface API, here is what it says for setStatus method:
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 defined in the web applicaion, the sendError method should be used instead.

That would explain why the SC_INTERNAL_SERVER_ERROR is not the correct answer.
 
Shubh Bhat
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get it at all! Can anyone explain?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic