[英]Redirect to jsp file in WEB-INF using Ajax
I'm using ajax to submit login form details in my web app. 我正在使用ajax在Web应用程序中提交登录表单详细信息。 If username and password are correct, i need to redirect user to
home.jsp
page in web-inf
folder. 如果用户名和密码正确,我需要将用户重定向到
web-inf
文件夹中的home.jsp
页面。
I have tried with requestdispatcher and it not worked. 我已经尝试过requestdispatcher,但是没有用。
Also tried as json.put("url", "/WEB-INF/home.jsp");
还尝试了
json.put("url", "/WEB-INF/home.jsp");
in my servlet and window.location = json.url;
在我的servlet和
window.location = json.url;
in javascript and it also not worked. 在JavaScript中,它也无法正常工作。
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 我的Servlet代码的一部分
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 WEB-INF中的任何内容都不是公共可访问的,您可能希望将用户重定向到servlet,从中可以将请求转发到WEB-INF中的home.jsp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.