• 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()

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Exam Study Kit p.97

The method setStatus(int sc) is similar to the sendError() methods in the sense that we may use it to set the status codes representing errors in the response. However, an important point about the setStatus method is that , unlike the sendError() methods, it does not trigger the container to generate an error page. It just sends the status code to the browser, which is displayed by the browser as per its setting

.
I don't really understand this sentence. I've tried this following simple code:

and my browser displays an blue/white 400 error page, as expected.
By adding a declarative error handling in my web.xml like this:

the redirection to the ExceptionHandlerServlet is well done also.
So what does the sentence mean exactly?
Thanks for your response,
Cyril.
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please tell me if I'm wrong in thinking that the sentence

setStatus() from javax.servlet.http.HttpServletResponse, unlike the sendError() methods, doesn't trigger the container to generate an error page


Indeed, with Tomcat, setStatus method trigger the container to generate a jakarta tomcat error page.
So what's the real difference between setStatus et sendError page, except that with setStatus we can't send a message?
I would be very grateful for any light on this topic,
Regards,
Cyril.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are good. The difference lies in the implementation of Servlet and JSP container. The specification of Servlet and JSP doesn't REQUIRE the container to generate the error page triggered by setStatus. However, it doesn't prohibit doing that either.
There are a lot of discrepancies between the specifications and implementation. So it is just a fact of life. Tomcat has a very good compliance with the specification, which doesn't necessarily mean it cannot exceed the specifications.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic