• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Question from JWebPlus  RSS feed

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is a question from JWebPlus.

Consider the following code snippets. What will be displayed on the browser when a GET request is sent to FirstServlet assuming that the buffer is large enough to hold all the data before sending the data to the client?



Select 1 correct option.

A Only Page1 and Page3

B Only Page2

C Page1, Page2, and Page3

D IllegalStateException at Runtime.

E Compilation Error.

the answer given is D, which is also correct, but since they are askingWhat will be displayed, I think B should be correct. when a request is "forwarded" to another resource, the buffer should be cleared of the contents generated by the forwarding resource. Therefore, only Page2 will be sent to the client. Now since FirstServlet is trying to write to the response IllegalStateException will be thrown, but that does not appear at client's browser...
I have tested this using tomcat 5.0.28, is it tomcat's behaviour or all the containers behave the same?

Regards,

Sushma
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what you said is correct!! in browser it will display "Page 2" and in the server side log file or console it will throw "IllegalStateException"..

Looks like error in JWebPlus. Since it is not freeware, is it not possible to get reply from them just curious..
 
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. This code wont throw any IllegalStateException. Only 'Page2' will be printed and the buffer of 1st servlet will be cleared before the forward so 'Page1' wont get printed. And if u make a forward and after that if u print something to response, it will be IGNORED. it would not cause any IllegalStateException. Any objections?
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I agree with Narayanan.

Thanks
 
Radmika Arunachalam
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry my answer is wrong.. I checked in tomcat it is not throwing ISException.. Thanks guys
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sushma, I just run that code. The result is the same as what you said.
I believe you are correct.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!