You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Lai <ml...@michael.lai.name> on 2005/09/20 05:16:42 UTC
Cannot forward after response has been committed
I have a jsp page that processes a login. The (simplified) code is
something like this:
<%@ page language="java"%>
<%
String userid = request.getParameter("userid");
String pw = request.getParameter("pw");
/* code to check user id and password */
if (user not found)
pageContext.forward("login.jsp");
else
pageContext.forward("userpage.jsp");
%>
Please note that nowhere in my jsp code do I use the "out" object or
send some outputs back to the client. Yet, I am getting this "Cannot
forward after response has been committed" error. If I comment out the
forward statements then the error disappears. Any help is appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Cannot forward after response has been committed
Posted by Michael Lai <ml...@michael.lai.name>.
I put a 'return' statement after every 'forward' statement in all my jsp
pages and now it seems to be working. Thanks for your feedback.
Actually, my linebreak occurs in the <% %> tags. I think my email
client might have reformatted my output before sending.
Tony@ServaCorp.com wrote:
>You want the line breaks, either line-feed or carriage-return, line-feed
>to occur within the java or jsp code, not within the html code.
>Sometimes the html is buffered and ignored when something else puts out
>headers or such.
>
>Within HTML, line breaks do not matter much
>Before HTML, any line break implies that HTML has started and you can get
>default headers without doing anything.
>Within JSP or Java, line breaks do not matter much.
>
>Choice of uglies.
><%@ page ...
>%><% code here
>
><%@ page ... %><%
>code here
>
><%@ page %>
>---there is here the line break of the above line---
><% at this point the response has been committed by outputting the above
>\r\n or whatever
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: Cannot forward after response has been committed
Posted by To...@ServaCorp.com.
You want the line breaks, either line-feed or carriage-return, line-feed
to occur within the java or jsp code, not within the html code.
Sometimes the html is buffered and ignored when something else puts out
headers or such.
Within HTML, line breaks do not matter much
Before HTML, any line break implies that HTML has started and you can get
default headers without doing anything.
Within JSP or Java, line breaks do not matter much.
Choice of uglies.
<%@ page ...
%><% code here
<%@ page ... %><%
code here
<%@ page %>
---there is here the line break of the above line---
<% at this point the response has been committed by outputting the above
\r\n or whatever
-----Original Message-----
From: Michael Lai [mailto:ml@michael.lai.name]
Sent: Monday, September 19, 2005 10:34 PM
To: Tomcat Users List
Subject: Re: Cannot forward after response has been committed
I have an index.jsp page that checks a user's access level:
<%@ page language="java" errorPage="" %> <--there is an html new-line
here!!!
<%
String userid = (String)session.getAttribute("UserId");
if (userid == null) {
pageContext.forward("login.jsp");
} else {
String access = (String)session.getAttribute("Access");
switch (access.charAt(0)) {
case 'A':
pageContext.forward("admin/index.jsp");
case 'R': case 'W':
pageContext.forward("db/index.jsp");
default:
pageContext.forward("login.jsp");
}
}
%>
And yet the above page works even with the <%@ page language="java" %>
line. I don't understand why the above code works but the doesn't work
for another page.
What do you propose -- that I remove the <%@ page... %> line?
Tony@ServaCorp.com wrote:
>Actually, the line end after the first line is sent back to the client,
>with apropriate html headers invented.
><%@ page language="java"%><% // now the line end is in java not in html
>
>Yep, looks ugly.
>What is even worse is code that sends a redirect and does NOT do a return.
>
>-----Original Message-----
>From: Michael Lai [mailto:ml@michael.lai.name]
>Sent: Monday, September 19, 2005 10:17 PM
>To: Tomcat Users List
>Subject: Cannot forward after response has been committed
>
>
>I have a jsp page that processes a login. The (simplified) code is
>something like this:
>
><%@ page language="java"%>
><%
>String userid = request.getParameter("userid");
>String pw = request.getParameter("pw");
>
>/* code to check user id and password */
>
>if (user not found)
> pageContext.forward("login.jsp");
>else
> pageContext.forward("userpage.jsp");
>%>
>
>Please note that nowhere in my jsp code do I use the "out" object or
>send some outputs back to the client. Yet, I am getting this "Cannot
>forward after response has been committed" error. If I comment out the
>forward statements then the error disappears. Any help is appreciated.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Cannot forward after response has been committed
Posted by Michael Lai <ml...@michael.lai.name>.
I have an index.jsp page that checks a user's access level:
<%@ page language="java" errorPage="" %>
<%
String userid = (String)session.getAttribute("UserId");
if (userid == null) {
pageContext.forward("login.jsp");
} else {
String access = (String)session.getAttribute("Access");
switch (access.charAt(0)) {
case 'A':
pageContext.forward("admin/index.jsp");
case 'R': case 'W':
pageContext.forward("db/index.jsp");
default:
pageContext.forward("login.jsp");
}
}
%>
And yet the above page works even with the <%@ page language="java" %>
line. I don't understand why the above code works but the doesn't work
for another page.
What do you propose -- that I remove the <%@ page... %> line?
Tony@ServaCorp.com wrote:
>Actually, the line end after the first line is sent back to the client,
>with apropriate html headers invented.
><%@ page language="java"%><% // now the line end is in java not in html
>
>Yep, looks ugly.
>What is even worse is code that sends a redirect and does NOT do a return.
>
>-----Original Message-----
>From: Michael Lai [mailto:ml@michael.lai.name]
>Sent: Monday, September 19, 2005 10:17 PM
>To: Tomcat Users List
>Subject: Cannot forward after response has been committed
>
>
>I have a jsp page that processes a login. The (simplified) code is
>something like this:
>
><%@ page language="java"%>
><%
>String userid = request.getParameter("userid");
>String pw = request.getParameter("pw");
>
>/* code to check user id and password */
>
>if (user not found)
> pageContext.forward("login.jsp");
>else
> pageContext.forward("userpage.jsp");
>%>
>
>Please note that nowhere in my jsp code do I use the "out" object or
>send some outputs back to the client. Yet, I am getting this "Cannot
>forward after response has been committed" error. If I comment out the
>forward statements then the error disappears. Any help is appreciated.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: Cannot forward after response has been committed
Posted by To...@ServaCorp.com.
Actually, the line end after the first line is sent back to the client,
with apropriate html headers invented.
<%@ page language="java"%><% // now the line end is in java not in html
Yep, looks ugly.
What is even worse is code that sends a redirect and does NOT do a return.
-----Original Message-----
From: Michael Lai [mailto:ml@michael.lai.name]
Sent: Monday, September 19, 2005 10:17 PM
To: Tomcat Users List
Subject: Cannot forward after response has been committed
I have a jsp page that processes a login. The (simplified) code is
something like this:
<%@ page language="java"%>
<%
String userid = request.getParameter("userid");
String pw = request.getParameter("pw");
/* code to check user id and password */
if (user not found)
pageContext.forward("login.jsp");
else
pageContext.forward("userpage.jsp");
%>
Please note that nowhere in my jsp code do I use the "out" object or
send some outputs back to the client. Yet, I am getting this "Cannot
forward after response has been committed" error. If I comment out the
forward statements then the error disappears. Any help is appreciated.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org