如果用户登录ie浏览器并在登录后重定向到index.jsp
,请复制此网址并粘贴到另一个浏览器chrome,这样它就会重定向到登录页面,以防止直接访问index.jsp
。
我引入了sessionInterceptor
以防止直接访问index.jsp
(应重定向到login.html
)。代码正在使用preHandle()
方法并运行所有代码,但在返回false
后,它不会重定向到login.html
。怎么了?
public class LoggingInterceptor implements HandlerInterceptor {
public static Logger LOG = LoggerFactory.getLogger(LoggingInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
HttpSession session = request.getSession();
if (session.getAttribute("isUserLoggedIn") == null) {
response.sendRedirect(request.getContextPath() + "/login.html");
return false;
}
System.out.println(request.getSession() + "--Before Method ");
System.out.println("---Before Method Execution---");
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// TODO Auto-generated method stub
System.out.println(request.getSession()+ "---post Method ");
System.out.println("---post Method Execution---");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
// TODO Auto-generated method stub
System.out.println(request.getSession() + "---after Method ");
System.out.println("---after Method Execution---");
}
}