It's not a secret anymore!*
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 Spring in Action this week in the Spring 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Cannot forward after response has been committed