wood burning stoves*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question (From Head First Servlets and JSPs) 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 Head First Servlets and JSPs)" Watch "Question (From Head First Servlets and JSPs)" New topic
Author

Question (From Head First Servlets and JSPs)

Eurig Jones
Ranch Hand

Joined: Feb 05, 2008
Posts: 57
When using a RequestDispatcher, the use of which methods can often lead to an IllegalStateException? (Choose All that Apply)

A. read
B. flush
C. write
D. getOutputStream
E. getResourceAsStream


The answer according to the book is B and C.

This question confuses me because:
- Question implies that the methods are part of RequestDispatcher. They aren't!
- The book states that it's flush you should only be worried about because it sends the response to the client. even though write is listed in the same piece of code.
- According to this link, getOutputStream would also cause an IllegalStateException

Is this an incorrect answer? If so, what is the correct answer?

Please help,
Eurig
[ August 29, 2008: Message edited by: Eurig Jones ]
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Hi Jones,

Whenever we do a forward using request dispatcher, container is suppose to clear the output buffer and then handover the request to another page.
Here IllegalStateException means we have already sent the response to client.
Genrally in the JSP page auto flush attribute is "true" which means you don't need to flush and also if on the writer object if you write the more than the size of buffer, output will be committed.
So if we take both the cases " write method can lead to Illegal state exception".

however on the servlet part if you flush the writer object after writing something, you will get the exception.

Getting a writer object will not cause the IllegalStateException. committing something on writer object will cause it.


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

Excellent sunny , I was also confused regarding the question.

best regards,
omi


Back to Java , again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question (From Head First Servlets and JSPs)