The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes RequestDispatcher forward 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 "RequestDispatcher forward" Watch "RequestDispatcher forward" New topic
Author

RequestDispatcher forward

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
hi,

I am calling the forward() method of the RequestDispatcher. After the call, in the calling servlet, is the response.isCommited method alway return true. That is, I want to know Does the response alway commited after call to forward method? Nothing is given in the Specifiactions.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Rodrigo Dinis
Ranch Hand

Joined: May 28, 2003
Posts: 40
Since you didnt call the flush method in the caller servlet/jsp the output stream inst closed and you can use the output stream in the calling servlet without matters. If you flush so a fat IllegalStateException will be throwed.


Rodrigo Dinis
SCEA
SCJWSD
SCJD
SCBCD
SCWCD
SCJP
CNA
Brasilia - BRASIL
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
I am not talking about closing of the out stream. After the forward method return to the calling Servlet, Can I use the out stream in any condition ?. In my testing the isCommited() method retrun alway true.


Thanks
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1066
Originally posted by Narendra Dhande:
After the forward method return to the calling Servlet, Can I use the out stream in any condition ?. In my testing the isCommited() method retrun alway true.


I always thought we were not supposed to have any code after a forward statement (apart from a return stmt).
Bhumika Thakkar
Ranch Hand

Joined: Apr 18, 2005
Posts: 79
Even after calling forward, we can have logic that does not write to the stream. Its not good programming but its valid.

Intuitively it makes sense that isCommited should return true after forwarding the request. if isCommited returns false then it would mean that we could write to the stream which is not correct.


SCBCD (Preparing) <br />SCWCD, 82%<br />SCJP, 90%
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

I want to know that the out.iscommited() method always return true or some case it can return false (i.e I can write to stream). For the sendError, sendRedirect methods of the HttpServletResponse it is clearly stated in Specs that After using these methods, the response should be considered to be committed and should not be written to. But for the forward() method for RequestDispatcher is is not specified anywhere. Though it is not good parctice to write after the forward method, I want to confirm it in view of Exam (There is seperate piont on RequestDispatcher)

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher forward