File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question from JWebPlus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question from JWebPlus" Watch "Question from JWebPlus" New topic

Question from JWebPlus

Sushma Sharma
Ranch Hand

Joined: Jun 02, 2005
Posts: 139
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?


Radmika Arunachalam
Ranch Hand

Joined: Mar 29, 2004
Posts: 45
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

Joined: Apr 01, 2005
Posts: 431
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?

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

I agree with Narayanan.


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Radmika Arunachalam
Ranch Hand

Joined: Mar 29, 2004
Posts: 45
Sorry my answer is wrong.. I checked in tomcat it is not throwing ISException.. Thanks guys
Sam Sun
Ranch Hand

Joined: Feb 01, 2005
Posts: 60
Sushma, I just run that code. The result is the same as what you said.
I believe you are correct.
I agree. Here's the link:
subject: Question from JWebPlus
jQuery in Action, 3rd edition