![]() |
JBridge: Certification Question Of The Day |
| JBridge Home >> Certification Questions >> Question for Sunday May 25th 2003 | Sunday May 25th 2003 |
|
Assume there is an error page set up in the deployment descriptor for error code 500. What true statements can then be made regarding the following servlet code?
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.write("Your error is about to be generated");
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
A It is inappropriate to use a status code of HttpServletResponse.SC_INTERNAL_SERVER_ERROR with the setStatus() method.
B If the doGet() method is run, the words "Your error is about to be generated" are ouput to the requester. C If the doGet() method is run, the error page defined in the web deployment descriptor is displayed. D The servlet will not compile. E The SC_INTERNAL_SERVER_ERROR value does not correspond to the value set up for the error code page in the web deployment descriptor. Page down for the answer... The AnswerA and C are the correct answers. It is inappropriate to use an error code (in the 400 and 500 series) with the setStatus method, which should be reserved for non-error outcomes (e.g. SC_OK or SC_MOVED_TEMPORARILY). Nonetheless, since the status SC_INTERNAL_SERVER_ERROR is set - which is status code 500 - this matches the error page set up, and so the error page is displayed. (I have tested this against the Tomcat standalone container, which is the reference implementation - it MAY be servlet container dependent. If you can clarify this, please email me). |
EMail: dbridgewater@jbridge.co.uk
Phone: +44 (0)1943 877414
Fax: +44 (0)1943 877414
Mail: David Bridgewater, Willow Dene, Bradford Road, Menston, Ilkley, West Yorkshire, LS29 6ED, UK
Copyright © 2003 David Bridgewater. All rights reserved.