Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendError

 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic