• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error: response already committed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
friends,
I have written code like this in JSP page

// lot of code is there
try{
/**
lot of code is there
*/
response.sendRedirect("_otherPage?name=value");
}
catch(Exception e)
{
System.out.println("error:" + e.getMessage());
}

I am running this code in Web Logic Server
At the point of
response.sendRedirect("_otherPage?name=value");
server giving error like this
error: response already committed
I am facing this problem since two days back. Before that it was working fine.
I restarted server also.

Any body could understand the problem?
Expecting responses from u.
thanks in advance
regds
mohan
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you probably have this jsp page included in another jsp page.
in that case, you can't use response.sendRedirect() because the response is already committed hence, the error...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sendRedirect doesn't halt the execution of the service method on it's own.
A good rule of thumb is to always follow sendRedirect (and requestDispatcher.forward) with a return statement unless you have follow up code that you want to run.

 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

/**
lot of code is there
*/
response.sendRedirect("_otherPage?name=value");
}



The problem is your "lot of code here".

A redirect depends upon being able to send response headers to the browser (which tell the browser to perform the redirect). Since the headers must be sent prior to any content, once any content at all has been sent, the opportunity for sending headers is gone. Therefore, once any content at all has been flushed, the response is considered "committed" and you can't do anything (including redirects) that involve headers.

You best bet is to make any redirect decisions before doing anything that might cause the response to commit -- or better yet, factor your processing out of the JSP page and into a controller servlet.
[ May 31, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know, if Ben and I keep bumping heads like this, we're going to end up joined at the foreheads!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
You know, if Ben and I keep bumping heads like this, we're going to end up joined at the foreheads!



Hehe..

To sum up all the responses....
Your code should:
  • Process the request
  • Determine whether or not to redirect
  • If Yes, redirect and

  • Either return immediately or be careful not to touch the output stream
    reply
      Bookmark Topic Watch Topic
    • New Topic