aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Response commited after using some methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Response commited after using some methods" Watch "Response commited after using some methods" New topic
Author

Response commited after using some methods

Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

Hi ranchers,

So far I know that after we using methods like: HttpServletResponse.sendRedirect, HttpServletResponse.sendError, the response should be considered to be committed and should not be written to. But is this concept also applicable for RequestDispatcher.forward? I am curious about this.


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
From the API:

forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

Thanks Mirko.

But what I meant is after RequestDispatcher.forward called, is the response also considered commited?
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
I am not sure if that would be exactly correct. All that RequestDispatcher does is forward the appropriate request and response object to the next destination (servlet or jsp).

Committing an output before or after it throws IllegalStateException. Correct me if i am wrong.


Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
I just read this somewhere ....Please confirm this is correct.

When the sendError() method is called, the response is assumed to be committed.
As per the API of the sendError() method, if you write to the response after calling sendError() then the data is ignored and no exception is thrown

Is this true for RequestDispatcher also?
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Sorry, I made a mistake.

I guess it should throw an IllegalStateException. Accordingly to section SRV.8.4 of the spec:


[ May 17, 2007: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Response commited after using some methods
 
Similar Threads
setStatus and sendError
RequestDispatcher forward
sendRedirect ( qsn from Study kit)
sendRedirect method
org.apache.soap.Envelope: How to read the returned envelope?