I've created a login form as
<div class="top1">
<span id="book_store">Book Store</span>
<div class="login_signup_form">
<input type="email" id="email_id" placeholder="Email" name="email" />
<input type="password" id="pas" placeholder="Password" name="password" />
<span id="wrongPass" style="font-size: 15px; color: red; display: none;">
Wrong Password
</span>
<button id="logIn">Log In</button>
<button id="signUp">Sign Up</button>
</div>
</div>
I am validating the email and password using ajax which is absolutely fine.
$("#logIn").click(function(){
var info = {
email: $("#email_id").val(),
password: $("#pas").val()
} ;
$.ajax({
type: 'POST',
url: 'login',
data: info,
success: function (data) {
if(data==="wrongPassword")
$("#wrongPass").show();
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
});
When password is wrong then error is shown on the same page but i want the Servlet to redirect the request to JSP page if password is correct. Servlet code is :
if(!pass.equals(tempPass))
{
writer.print("wrongPassword");
}
else
{
dispatcher = request.getRequestDispatcher("login.jsp");
dispatcher.forward(request,response);
}
wrong password case works fine but when password is correct then request is not redirected to login.jsp. I think it returns to ajax call. Can i break the ajax call return in else condition in servlet so that request is not returned to ajax call instead it is forwarded to jsp page??? PLZ help!!!!
It's not a duplicate question...
I want to redirect request from servlet to jsp. I've sent request to that servlet using ajax and trying to redirect the request to login.jsp in else block but it is not being directed...Same page remains in the window.