Click to See Complete Forum and Search --> : response.sendRedirect


phoebeching
03-22-2007, 07:48 PM
Hi, Good day,

I had the following code where I can't figure out how should I write. The situation is when a user login, if their ID was not found in the database, it will redirect them back to login page, else redirect them to homepage.

while (result.next()) {
if (result.wasNull()) {
response.sendRedirect("login.jsp");
}
else {
response.sendRedirect("home.jsp");
}
}

If I place the "response.sendRedirect("home.jsp");" outside the while loop, I will get this following error "java.lang.IllegalStateException".
Pls help. Thanks in advanced.

jasonahoule
03-25-2007, 04:55 PM
I'm not sure what is happening here. You may need to clear that up. One suggestion I can make is to be sure that this code occurs before any html is written (i.e. before the <html> tag) or else it will cause problems.

phoebeching
03-25-2007, 06:59 PM
Thanks Jason, I did a count on the record and continue on the redirect process. It works anyway.

WebLoader
04-04-2007, 07:53 AM
i don't know what 'result' indicated for? One suggestion i cam make as following code
private int SUCCESS =-1;
if(ResultSet != null){
// a java.lang.NullPointerException will be raised if ResultSet is a null object
// while calling its function next();
while (ResultSet .next()) {
if(validated){
SUCCESS = 0;
break;
}else{
continue;
}
}
}

if(SUCCESS == 0){
response.sendRedirect("/home.jsp");
}else{
response.sendRedirect("/login.jsp");
}

kumarp
04-18-2007, 06:40 AM
hi all,

i am new to java, can any body explains response.sendRedirect() and response.forward();