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?

[EMAIL PROTECTED] 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:[EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to