• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why it thorws IllegalStateException ?

 
David Chang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help to find out why the IllegalStateException on the follow codes ...
Thanks
<%
String uid = request.getParameter("userID");
String password = request.getParameter("userPassword");

System.out.println("(DEBUG): user_id = " + uid + ", user_passwd = " + password);

// 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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!