• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock question

 
green hand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question, can anybody advise, thanks.
11. public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException {
12. PrintWriter out = response.getWriter();
13. out.print(�<h1>Hello</h1>�);
14.
15. response.sendError(HttpServletResponse.SC_NOT_FOUND);
16.}
Which, inserted at line 14, will ensure that an IllegalStateException is NOT thrown at line 15?
A. response.flushBuffer();
B. response.resetBuffer();
C. response.clearStatus();
D. if(response.getError()==-1)
E. if(response.getStatus()==-1)
F. if(response.isCoxnnitted()==false)
 
Richard Miranda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is:
F. if(response.isCommitted()==false)
 
green hand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also think so, but oddly the answer is A
 
Richard Miranda
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The source you're looking at, is wrong about the answer.
In fact calling flushBuffer() before sendError() will increase the chances of causing a IllegalStateException !
 
Jeff Walker
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by green hand:
I have a question, can anybody advise, thanks.
11. public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException {
12. PrintWriter out = response.getWriter();
13. out.print(�<h1>Hello</h1>�);
14.
15. response.sendError(HttpServletResponse.SC_NOT_FOUND);
16.}
Which, inserted at line 14, will ensure that an IllegalStateException is NOT thrown at line 15?
A. response.flushBuffer();
B. response.resetBuffer();
C. response.clearStatus();
D. if(response.getError()==-1)
E. if(response.getStatus()==-1)
F. if(response.isCoxnnitted()==false)
 
Jeff Walker
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by green hand:
I have a question, can anybody advise, thanks.
11. public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException {
12. PrintWriter out = response.getWriter();
13. out.print(�<h1>Hello</h1>�);
14.
15. response.sendError(HttpServletResponse.SC_NOT_FOUND);
16.}
Which, inserted at line 14, will ensure that an IllegalStateException is NOT thrown at line 15?
A. response.flushBuffer();
B. response.resetBuffer();
C. response.clearStatus();
D. if(response.getError()==-1)
E. if(response.getStatus()==-1)
F. if(response.isCoxnnitted()==false)

response.FlushBuffer() itself will commit the response, as will response.resetBuffer() and response.clearStatus() seems to be a non-existent method, as do getError() and getStatus(). The answer is F. but it should read:
if(response.isCommitted()==false)
Note: I think the code would actually work anyway without the added line, but read the question, it asks what will ENSURE that the exception is not thrown ? F. is the only viable answer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic