File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Cannot forward after response has been committed" Watch "Cannot forward after response has been committed" New topic

Cannot forward after response has been committed

Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
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());

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(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
...... and so on
Does anyone know what is happening??
I really appreciate a quick answer..!!
Thanks in advance, Tom
Michael ness

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.
I agree. Here's the link:
subject: Cannot forward after response has been committed
It's not a secret anymore!