I'm struggling to redirect users to a specific page in my web app after successful login. I have attempted using requestdispatcher and manipulating JSON objects in my servlet, but so far nothing has worked.
My Approach
jQuery(document).ready(function() {
$('#user-login-form').submit(function() {
var postdata = $('#user-login-form').serialize();
$.ajax({
type: 'POST',
url: 'login',
data: postdata,
dataType: 'json',
success: function(json) {
if(json.errorMessage != '') {
alert(json.errorMessage);
} else{
// redirect code should go here
}
}
});
return false;
});
});
Part of my Servlet code
if (username.equals("admin") && password.equals("pass")) {
// logic for redirection
} else {
json.put("errorMessage", "Invalid username or password");
}
Any tips on how I can achieve this redirection?