Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setStatus Method of HttpServletResponse

 
Rishi Chopra
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have read some where that setStatus 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.

So According to this
Can i use setStatus Method to return SC_FORBIDDEN(403) error back to the client browser.

Regards
Rishi
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what the api has to say about this method

setStatus

public void setStatus(int sc,
java.lang.String sm)

Deprecated. As of version 2.1, due to ambiguous meaning of the message parameter. To set a status code use setStatus(int), to send an error with a description use sendError(int, String). Sets the status code and message for this response.

Parameters:
sc - the status code
sm - the status message


hth
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't set the status, then 200 (OK) is assumed.

403 is useful if you want to handle authentication in your own code (instead of letting the servlet container handle it for you). Something like the following will cause the authentication dialog to be shown to the user:



If you just want to say "you can't get in here", and not show the dialog, leave out the setHeader call.
[ March 04, 2007: Message edited by: Ulf Dittmer ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic