关于用户身份验证方法
如题:我的目的是想在用户尚未登陆时,访问其他的页面都会返回到登录界面,
做好能写在过滤类里,我想了一个方法,但觉得这样作不太好
HttpSession session = ((HttpServletRequest) request).getSession();
String path = ((HttpServletRequest) request).getRequestURI();
if (path.endsWith("login.jsp")||path.endsWith("login.do")) {
} else {
if (session.getAttribute("user") == null) {
((HttpServletResponse) response).sendRedirect("/book/jsp/login.jsp");
}
}
有没一什么好的方法啊,我想可能关键的问题是如果区分第一次访问,
也就是说当我第一次访问login.jsp根本不需要进行验证,访问其他页面时其他页面就跳到登陆界面
以后访问其他页面是就需要进行验证,
有没一什么好的方法阿,高手们!