【发布时间】:2015-01-07 18:49:18
【问题描述】:
我有两个应用程序在同一个服务器(Tomcat 7)下运行
在第一个应用程序下,我有一个包含用户名和密码字段的登录页面。
单击登录按钮时,我正在调用 Jersey RESTFUL 服务(不同的应用程序)。
<html>
<head>
<title>Login Page 122</title>
</head>
<body>
<form action="LoginServlet" method="post">
Username: <input type="text" name="user">
<br>
Password: <input type="password" name="pwd">
<br>
<input type="button" value="Login User" onclick="LoginAdmin()">
</form>
</body>
</html>
function LoginAdmin() {
$.ajax({
type: 'GET',
url: url + '/RFS/admin/adminlogin?UUID=' + UUID ,
//contentType: 'application/json; charset=utf-8',
jsonpCallback: 'jsonCallback',
cache: true,
dataType: 'jsonp',
jsonp: false,
success: function (response) {
var testdata = JSON.stringify(response);
},
});
}
RESTFUL 服务将根据数据库验证数据,如果成功 我在 HttpSession 中设置一个属性。
session.setAttribute("user","LoggedIN");
在 Application First 下,我编写了一个过滤器,它可以保护 HTML 资源在没有用户登录的情况下直接访问。
现在在我的过滤器中,我试图在我的 servlet 过滤器中使用该会话属性。
但问题是两者都是两个不同的应用程序都有两个不同的会话
所以我得到的会话属性总是空的原因
public class AuthenticationFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String uri = req.getRequestURI();
this.context.log("Requested Resource::"+uri);
HttpSession session = req.getSession(false);
if(session == null || !session.getAttribute("user").toString().equals("LoggedIN")){
this.context.log("Unauthorized access request");
System.out.println("Into session is null condition");
res.sendRedirect("login.html");
}else{
System.out.println("Into chain do filter");
chain.doFilter(request, response);
}
}
public void destroy() {
}
}
有什么办法可以解决这个问题吗??
【问题讨论】: