This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Cannot forward after response has been committed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Cannot forward after response has been committed" Watch "Cannot forward after response has been committed" New topic
Author

Cannot forward after response has been committed

Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
Hello!
My web hotel upgraded from Tomcat 3.X to 4.1.18 yesterday and now my site doesn't work anymore.
I have a html page where users fill out their username and password. It's a form which posts to a jsp login page. That one looks (partially) like this:
if (myBean.login(username, password))
{
session.setAttribute("firstname", myBean.getFirstname());
session.setAttribute("lastname", myBean.getLastname());
session.setAttribute("userid", myBean.getUserId());
response.sendRedirect("index2.jsp");

This worked fine before but now I get:
org.apache.jasper.JasperException: Cannot forward after response has been committed
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
...... and so on
Does anyone know what is happening??
I really appreciate a quick answer..!!
Thanks in advance, Tom
Michael ness
Greenhorn

Joined: Sep 09, 2002
Posts: 7
Hi Thomas,
This usually occurs because you have tried to output something to the browser before calling
response.sendRedirect. There is a buffer that as you send output fills up once it is full it is flushed and you can no longer redirect to another page. One solution is to increase the size of the buffer by using the following
<%@ page buffer="48k" autoFlush="true" %>
I think the default is 15k. However the better solution is just to make sure your not outputting anything before calling response.sendRedirect.
Michael
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot forward after response has been committed
 
Similar Threads
RequestDispatcher and .forward()
Jasper Report Export PDF Problem.
jsp error
IlligalStateException
Problems with jsp:include