Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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: 3953
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!