Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Response commited after using some methods

 
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.
 
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?
 
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?
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • 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 ]
 
grapes are vegan food pellets. Eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic