• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTPServletResponse sendRedirect

 
vivek makode
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Why and when does this method throw an IllegalStateException?
The API says this...."If the response has already been committed, this method throws an IllegalStateException" .
What actually is meant by response already committed? how can i solve this problem?
KIndly respond. This exception has been bugging me since long in my current project.
Thanking you in advance.
Vivek
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The response is comitted as soon as you start sending data to the client. This isn't quite straigh-forward, since the first stuff you send to the client is usually buffered by the output stream, so you may be able to write some data before this buffer fills and the response is comitted.
What this means is that as soon as you begin responding with the contents of a page, you can't suddenly change your mind and decide to send something different. It's too late. Fot this reason it's best to have a controller that decides where the output will come from, but doesn't send any data.
Some people think that you can get around this by increasing the size of the buffer and not using a controller, but this is pretty weak code. It's far better to create a stable solution first time around. One important point is that some actions may cause the buffer to flush before it fills, and in this case it doesn't matter how big the buffer is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic