I'm using ajax to submit login form details in my web app. If username and password are correct, i need to redirect user to home.jsp
page in web-inf
folder.
I have tried with requestdispatcher and it not worked.
Also tried as json.put("url", "/WEB-INF/home.jsp");
in my servlet and window.location = json.url;
in javascript and it also not worked.
My Script
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 to jsp file in web-inf
}
}
});
return false;
});
});
Part of my Servlet code
if (username.equals("admin") && password.equals("pass")) {
// in here, i need to redirect user to home.jsp page in web-inf folder
} else {
json.put("errorMessage", "Invalid username or password");
}
How can i do this ?
You can redirect user to only publicly available resources,
anything inside WEB-INF isn't publicly accessible , you might want to redirect user to a servlet from where you can forward request to your home.jsp inside WEB-INF
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.