Please help to find out why the IllegalStateException on the follow codes ... Thanks <% String uid = request.getParameter("userID"); String password = request.getParameter("userPassword");
// Check if user is registered try { if ( !mydb.findUserID(uid) ) response.sendRedirect("login.jsp?error=yes&name=" + uid + "&reason=newUser"); } catch (Exception e) { mydb.close(); System.out.println(e); // response.sendRedirect("errorHandler.jsp?type=exception"); }
if ( verifyPasswordPolicy(password) ) { // session.setAttribute("IsLoggedIn", "true"); login.setLoggedIn(true); response.sendRedirect("buildOrder.jsp"); } else { // ??? - This will cause IllegalStateException response.sendRedirect("login.jsp?error=yes&name=" + uid); } %>
boyet silverio
Ranch Hand
Joined: Aug 28, 2002
Posts: 173
posted
0
hello David, going thru your code, there is the possibility that your response.redirect() will be executed twice, which commits the response twice. This causes the error IllegalStateException. That is, the container will sense that the response has already been committed in the first response.sendRedirect, so upon seeing the second redirect, it will throw up the exception. You should try to work up your code to avoid this possibility.