• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mock question

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer is:
F. if(response.isCommitted()==false)
 
green hand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
This is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic