Meaningless Drivel is fun!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes sendError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sendError" Watch "sendError" New topic
Author

sendError

Aaron Raja
Ranch Hand

Joined: Jun 07, 2007
Posts: 206
Consider the code of the doPost() method of a servlet shown in the exhibit.

Assuming that getNameFromDBSomeHow() returns null, which of the following statements regarding this code are correct if the buffer is large enough to accumulate all the data before sending it to the client?

public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
System.out.println("Inside doPost");
PrintWriter out = response.getWriter();
out.println("Hello, ");
String name = getNameFromDBSomeHow();
if(name == null)
{
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to get name.");
}
out.println(name);
}

a) It will not throw any exception.
b) It will throw an IllegalStateException at runtime.
c) It will throw NullPointerException.
d) It will throw a ServletException.
e) It will throw an InvalidStateException.


Why answer is (a)
can any body explain out come of
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to get name.");
Thanks
AR


Thanks, AR
SCWCD 5, SCJP 1.4, OCA (PL/SQL)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Please QuoteYourSources.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sendError
 
Similar Threads
bytearray image decoding
some questions on J2EE test
sendRedirect ( qsn from Study kit)
doubt in Exam Kit Book
response commitment