Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Response commited after using some methods

 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mirko.

But what I meant is after RequestDispatcher.forward called, is the response also considered commited?
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic