IntelliJ Java IDE
The moose likes JSP and the fly likes Why it thorws IllegalStateException ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Why it thorws IllegalStateException ?" Watch "Why it thorws IllegalStateException ?" New topic
Author

Why it thorws IllegalStateException ?

David Chang
Greenhorn

Joined: Feb 09, 2003
Posts: 1
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

Joined: Aug 28, 2002
Posts: 173
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.
 
IntelliJ Java IDE
 
subject: Why it thorws IllegalStateException ?
 
Threads others viewed
To show the Error message at the login.jsp page using servlet
SessionServlet and Login.jsp
Error in JDBC ODBC
Help with this code!
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Optional feature not
MyEclipse, The Clear Choice