Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setStatus()

 
riohk kurn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we use setStatus() plus <error-code> to replace sendError()?
 
Sam Tilley
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setStatus() does not trigger the container to generate an error page, it just sends the status code to teh browser, which is then displayed by the browser. So it should only be used for setting non-error status codes, eg SC_OK
I think <error-page> only works with sendError()
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I think that <error-page> & sendError() are 2 different things.sendError() is for sending messages like SC_UNAUTHORIZED explicitly while if some error occurs in your application then the page in error-page is shown.
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CMIW
<error-page> has associated exception OR error code.
I think if you are using sendError(), then it should display server's default error page for it rather than associated error page in web.xml.
I dont have tomcat here with me.. do try and tell us too
 
Marcelo Sousa Ancelmo
Ranch Hand
Posts: 498
Eclipse IDE Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendError trigger the container about the status code of the error, then if you have in your DD:

And in your jsp or servlet code:

If for any reason this code is executed, then will be served for the client the forbid.jsp page.
For 404, if you have inside the context of the web application any request for a resource that doesn't exist, you don't have to explicity call sendError(), the container just call the page mapped in the DD.
[ November 22, 2002: Message edited by: Marcelo Sousa Ancelmo ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic