登录拦截器,多级跳转

使用springMVC。

request.getRequestDispatcher("/login.jsp").forward(request, response);

在页面嵌套有多级,当子页面被拦截时,子页面跳转到了登录页面,明显这种效果是错误的,需要整个都跳转到首页。

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		//如果是登录则放行
		if(request.getRequestURI().indexOf("/login/checkLogin.action")>=0){
			return true;
		}
		HttpSession session = request.getSession();
		//如果用户已登录也放行
		if(session.getAttribute("user")!=null){
			return true;
		}
		//用户没有登录到登录页面
		PrintWriter out = response.getWriter();  
          out.println("<html>");      
          out.println("<script>");      
          out.println("window.open ('"+request.getContextPath()+"/login.jsp','_top')");      
          out.println("</script>");      
          out.println("</html>");    
		//request.getRequestDispatcher("/login.jsp").forward(request, response);
		return false;	
	}
无论哪一级页面拦截都将跳转到登录首页,感谢大神。
参考:http://blog.csdn.net/judyfun/article/details/42393455


猜你喜欢

转载自blog.csdn.net/sinat_38314794/article/details/79261539