I have an application where i have to redirect from a login page to another page the user name and the password i enter in the login page is going to another servlet.so from the servlet if i found the login values are matched i will redirect to another page,But this things are not working....I am posting my code
boolean validationFlag = qb.userValidation(loginVO);
if (validationFlag) {
//This is for Ajax return
System.out.println("we are here");
response.sendRedirect("../main.jsp");
System.out.println("we are back");
}
} catch (Exception e) {
e.printStackTrace();
}
}
here validationFlag is true and i have to redirect to anther page but it is not working
You have to return afterwards. Otherwise, execution keeps going until the end of the JSP/servlet.
response.sendRedirect("../main.jsp");
return;
So without the return, your System.out.println("we are back"); will be executed.
First of all get clear with concept of when to use sendRedirect and when to use RequestDispatcher. (you are using 2 step process for simple validation)
http://www.beingjavaguys.com/2013/05/difference-between-request-dispatcher.html http://www.coderanch.com/t/540671/Servlets/java/difference-RequestDispatcher-sendRedirect
remove those println statements. Remember you can't do sendRedirect() after writing to response object.
And now try,
RequestDispatcher view = request.getRequestDispatcher("main.jsp");
view.forward(request, response);
here there is no problem of relative urls like the one you were using.
Hope this helps....happy coding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With