Re: IllegalStateException Error
try reset() ing the response before sending the redirect. You should not write to the response object if you are going to redirect/forward it to another resources that will output to the response object. response.reset(); also redirecting will not stop the thread from executing the remainder of the code so you should put in a return statement after the redirect On Thu, 2002-10-17 at 11:12, Lior Shliechkorn wrote: From:Carl [EMAIL PROTECTED] on 10/17/2002 09:12 AM MST I'm trying to do some checking on my pages that make sure that the user logged out and all the attributes that were bounded to the session were destroyed (using session.invalidate() in the logout page). However, I'm running into difficulties with 1 of my pages. The check works fine on all the other pages except this one. I try to response.sendRedirect() the page to the login page again, but it seems to ignore it and I get errors that I can't forward after a response has been committed. And other times it logs the user right back in as if nothing happened after the user logged out...it's only with this one page. here's the code. I'm not sure what could be wrong: %@ page session=true % %@ page contentType=text/html;charset=WINDOWS-1252 % %@ page import = java.util.*, java.sql.*, java.util.Vector.* % jsp:useBean id=pool class=ConnectionPool scope=application / % response.setHeader(pragma, no-cache); response.setHeader(Cache-Control, no-cache); response.setHeader(Expires, 0); Connection conn = null; String asql = null; Statement stmt = null; ResultSet rs = null; String aUserID = null; String aPassword = null; try { FB user = (FB) session.getAttribute(bean); //*** // FormBean Exists //*** if (user != null) { aUserID = user.getUSER_ID(); aPassword = user.getPASSWORD(); } //*** // No session bean exists //*** else { response.sendRedirect(../html/ReLogin.html); } // // INITIALIZE THE POOL // if (pool.getDriver() == null) { pool.init(); pool.initializePool();
IllegalStateException Error
I'm trying to do some checking on my pages that make sure that the user logged out and all the attributes that were bounded to the session were destroyed (using session.invalidate() in the logout page). However, I'm running into difficulties with 1 of my pages. The check works fine on all the other pages except this one. I try to response.sendRedirect() the page to the login page again, but it seems to ignore it and I get errors that I can't forward after a response has been committed. And other times it logs the user right back in as if nothing happened after the user logged out...it's only with this one page. here's the code. I'm not sure what could be wrong: % page session=true % % page contentType=text/html;charset=WINDOWS-1252 % % page import = java.util.*, java.sql.*, java.util.Vector.* % jsp:useBean id=pool class=ConnectionPool scope=application / % response.setHeader(pragma, no-cache); response.setHeader(Cache-Control, no-cache); response.setHeader(Expires, 0); Connection conn = null; String asql = null; Statement stmt = null; ResultSet rs = null; String aUserID = null; String aPassword = null; try { FB user = (FB) session.getAttribute(bean); //*** // FormBean Exists //*** if (user != null) { aUserID = user.getUSER_ID(); aPassword = user.getPASSWORD(); } //*** // No session bean exists //*** else { response.sendRedirect(../html/ReLogin.html); } // // INITIALIZE THE POOL // if (pool.getDriver() == null) { pool.init(); pool.initializePool(); } boolean aloginflag = false; conn = pool.getConnection(); stmt = conn.createStatement(); asql = getSqlStatement(); System.out.println(asql); String accesscode = null; rs = stmt.executeQuery(asql); while (rs.next()) { aloginflag = true; System.out.println(Login successful!); accesscode = rs.getString(ACCESS_CODE); user.setACCESSCODE(accesscode); System.out.println(accesscode); } // end while if(aloginflag) {} else { % jsp:forward page=../html/LoginError.html/jsp:forward % } if (accesscode.equalsIgnoreCase(B)) { % jsp:forward page=daily.jsp/jsp:forward % } // end if else if (accesscode.equalsIgnoreCase(C)) { % jsp:forward page=report2.jsp/jsp:forward % } // end else if else if (accesscode.equalsIgnoreCase(G)) { % jsp:forward page=report.jsp/jsp:forward % } // end else if else if (accesscode.equalsIgnoreCase(U)) { % jsp:forward page=news.jsp/jsp:forward % } // end else if else { System.out.println(No account found in the database!); response.sendRedirect(../html/LoginError.html); } // end else } catch(SQLException e) { // Login SQL Error! response.sendRedirect(../html/LoginError.html); } catch(ClassNotFoundException e) { // Classname Error! response.sendRedirect(../html/DBConnError.html); } finally { try { if (stmt != null) stmt.close(); if (rs != null) rs.close(); if (conn != null ) pool.releaseConnection(conn); } catch (Exception sqlex) { response.sendRedirect(../html/LoginError.html); } } % I find that it totally disregards the lines after the TRY statement and even after I log out I can still see that when I hit the back button it process the sql query and doesn't redirect. I tried to change the else (after the aloginflag) to a response.sendRedirect() and the page breaks... What am I doing wrong? Thanks, Lior - Do you Yahoo!? Faith Hill - Exclusive Performances, Videos, more faith.yahoo.com
RE: IllegalStateException Error
ok, several problems here: 1. place a 'return;' after your sendRedirect() 2. remove unintended whitespace from your jsp: change % jsp:forward page=daily.jsp/jsp:forward % to %jsp:forward page=daily.jsp/jsp:forward% 3. post your error messages with stack trace. I happen to recognize 'response already committed', but others may not. 4. search the archives: http://www.mail-archive.com/tomcat-user%40jakarta.apache.org/ Illegalstateexception returns many hits and 'response already committed' returns more specific to your problem. These will probably give you more detail than I can remember right now. #3 and #4 will help you get an answer quicker. Please also remember that not everyone gets to all messages on the list within the 3 hours that you have allowed. Charlie -Original Message- From: Lior Shliechkorn [mailto:liorshliech;yahoo.com] Sent: Thursday, October 17, 2002 12:12 PM To: Tomcat Subject: IllegalStateException Error I'm trying to do some checking on my pages that make sure that the user logged out and all the attributes that were bounded to the session were destroyed (using session.invalidate() in the logout page). However, I'm running into difficulties with 1 of my pages. The check works fine on all the other pages except this one. I try to response.sendRedirect() the page to the login page again, but it seems to ignore it and I get errors that I can't forward after a response has been committed. And other times it logs the user right back in as if nothing happened after the user logged out...it's only with this one page. here's the code. I'm not sure what could be wrong: % page session=true % % page contentType=text/html;charset=WINDOWS-1252 % % page import = java.util.*, java.sql.*, java.util.Vector.* % jsp:useBean id=pool class=ConnectionPool scope=application / % response.setHeader(pragma, no-cache); response.setHeader(Cache-Control, no-cache); response.setHeader(Expires, 0); Connection conn = null; String asql = null; Statement stmt = null; ResultSet rs = null; String aUserID = null; String aPassword = null; try { FB user = (FB) session.getAttribute(bean); //*** // FormBean Exists //*** if (user != null) { aUserID = user.getUSER_ID(); aPassword = user.getPASSWORD(); } //*** // No session bean exists //*** else { response.sendRedirect(../html/ReLogin.html); } // // INITIALIZE THE POOL // if (pool.getDriver() == null) { pool.init(); pool.initializePool(); } boolean aloginflag = false; conn = pool.getConnection(); stmt = conn.createStatement(); asql = getSqlStatement(); System.out.println(asql); String accesscode = null; rs = stmt.executeQuery(asql); while (rs.next()) { aloginflag = true; System.out.println(Login successful!); accesscode = rs.getString(ACCESS_CODE); user.setACCESSCODE(accesscode); System.out.println(accesscode); } // end while if(aloginflag) {} else { % jsp:forward page=../html/LoginError.html/jsp:forward % } if (accesscode.equalsIgnoreCase(B)) { % jsp:forward page=daily.jsp/jsp:forward % } // end if else if (accesscode.equalsIgnoreCase(C)) { % jsp:forward page=report2.jsp/jsp:forward % } // end else if else if (accesscode.equalsIgnoreCase(G)) { % jsp:forward page=report.jsp/jsp:forward % } // end else if else if (accesscode.equalsIgnoreCase(U)) { % jsp:forward page=news.jsp/jsp:forward % } // end else if else { System.out.println(No account found in the database!); response.sendRedirect(../html/LoginError.html); } // end else } catch(SQLException e) { // Login SQL Error! response.sendRedirect(../html/LoginError.html); } catch(ClassNotFoundException e) { // Classname Error! response.sendRedirect(../html/DBConnError.html); } finally { try { if (stmt != null) stmt.close(); if (rs != null) rs.close(); if (conn != null ) pool.releaseConnection(conn); } catch (Exception sqlex) { response.sendRedirect(../html/LoginError.html); } } % I find that it totally disregards
RE: IllegalStateException Error
The return works. Thanks. I still really don't understand what was happening that it was committing the response. It was giving me a java.lang.IllegalStateException : cannot forward response has been committed... And it only gives me this error on this page...the other pages have the same exact code with checking the session beans and it works. Strange. Cox, Charlie [EMAIL PROTECTED] wrote:ok, several problems here: 1. place a 'return;' after your sendRedirect() 2. remove unintended whitespace from your jsp: change % to % 3. post your error messages with stack trace. I happen to recognize 'response already committed', but others may not. 4. search the archives: http://www.mail-archive.com/tomcat-user%40jakarta.apache.org/ Illegalstateexception returns many hits and 'response already committed' returns more specific to your problem. These will probably give you more detail than I can remember right now. #3 and #4 will help you get an answer quicker. Please also remember that not everyone gets to all messages on the list within the 3 hours that you have allowed. Charlie -Original Message- From: Lior Shliechkorn [mailto:liorshliech;yahoo.com] Sent: Thursday, October 17, 2002 12:12 PM To: Tomcat Subject: IllegalStateException Error I'm trying to do some checking on my pages that make sure that the user logged out and all the attributes that were bounded to the session were destroyed (using session.invalidate() in the logout page). However, I'm running into difficulties with 1 of my pages. The check works fine on all the other pages except this one. I try to response.sendRedirect() the page to the login page again, but it seems to ignore it and I get errors that I can't forward after a response has been committed. And other times it logs the user right back in as if nothing happened after the user logged out...it's only with this one page. here's the code. I'm not sure what could be wrong: response.setHeader(pragma, no-cache); response.setHeader(Cache-Control, no-cache); response.setHeader(Expires, 0); Connection conn = null; String asql = null; Statement stmt = null; ResultSet rs = null; String aUserID = null; String aPassword = null; try { FB user = (FB) session.getAttribute(bean); //*** // FormBean Exists //*** if (user != null) { aUserID = user.getUSER_ID(); aPassword = user.getPASSWORD(); } //*** // No session bean exists //*** else { response.sendRedirect(../html/ReLogin.html); } // // INITIALIZE THE POOL // if (pool.getDriver() == null) { pool.init(); pool.initializePool(); } boolean aloginflag = false; conn = pool.getConnection(); stmt = conn.createStatement(); asql = getSqlStatement(); System.out.println(asql); String accesscode = null; rs = stmt.executeQuery(asql); while (rs.next()) { aloginflag = true; System.out.println(Login successful!); accesscode = rs.getString(ACCESS_CODE); user.setACCESSCODE(accesscode); System.out.println(accesscode); } // end while if(aloginflag) {} else { % } if (accesscode.equalsIgnoreCase(B)) { % } // end if else if (accesscode.equalsIgnoreCase(C)) { % } // end else if else if (accesscode.equalsIgnoreCase(G)) { % } // end else if else if (accesscode.equalsIgnoreCase(U)) { % } // end else if else { System.out.println(No account found in the database!); response.sendRedirect(../html/LoginError.html); } // end else } catch(SQLException e) { // Login SQL Error! response.sendRedirect(../html/LoginError.html); } catch(ClassNotFoundException e) { // Classname Error! response.sendRedirect(../html/DBConnError.html); } finally { try { if (stmt != null) stmt.close(); if (rs != null) rs.close(); if (conn != null ) pool.releaseConnection(conn); } catch (Exception sqlex) { response.sendRedirect(../html/LoginError.html); } } % I find that it totally disregards the lines after the TRY statement and even after I log out I can still see that when I hit the back button it process the sql query and doesn't
AW: IllegalStateException Error
Because there are some factors that vary with every page to . - The size of output created by the caller of forward - The time the caller needs to create the output - The time that tomcat needs between calling forward and performing the check if the response has already been committed Note that the last 2 factors may vary depending on the load of the server. -Ursprüngliche Nachricht- Von: Lior Shliechkorn [mailto:liorshliech;yahoo.com] Gesendet: Donnerstag, 17. Oktober 2002 23:13 An: Tomcat Users List Betreff: RE: IllegalStateException Error The return works. Thanks. I still really don't understand what was happening that it was committing the response. It was giving me a java.lang.IllegalStateException : cannot forward response has been committed... And it only gives me this error on this page...the other pages have the same exact code with checking the session beans and it works. Strange. -- To unsubscribe, e-mail: mailto:tomcat-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:tomcat-user-help;jakarta.apache.org