JBridge

JBridge: Certification Question Of The Day

JBridge Home >> Certification Questions >> Question for Monday May 26th 2003 Monday May 26th 2003

What are users most likely to see in their browser if they make a request to the following servlet code? (1 correct answer)

protected void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
  PrintWriter out = response.getWriter();
  out.write("Your non-error is about to be sent");
  response.sendError(HttpServletResponse.SC_OK);
}


A An "Internal Server Error" page (resulting from an IllegalStateException on the server).
B A page displaying the words "Your non-error is about to be sent".
C A general-purpose page indicating that an error has occurred.
D A blank page.
Page down for the answer...











































The Answer

OK - this is a dumb question. Who would send an OK status code with the sendError() method? It doesn't make sense.
However, the outcome is mildly interesting for teaching purposes!
The correct answer is D, a blank web page results. Why should this be? When sendError() is used, the response body is cleared out. Usually, the response body would then be replaced with an HTML-formatted error message. However, there is not an HTML-formatted error message to correspond with an "OK" status - hence a blank page.

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.