Filter拦截跳出FrameSet

1、在项目中我们用Filter拦截判断session是否已失效或已超时,若如此则跳转至登陆页。

如下:

public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		// TODO 自动生成的方法存根
				HttpServletRequest request = (HttpServletRequest) req;
				HttpServletResponse response = (HttpServletResponse) resp;
		        if(request.getSession().getAttribute("userId")==null||request.getSession(false)==null){
		        	response.getWriter().println("<script>");
		        	response.getWriter().println("self.top.location.href='/CISS/theme/current/loginform.html'");
		        	response.getWriter().println("</script>");
		        }else{
		            chain.doFilter(request, response);
		        }
	}

并用Filter配置多个拦截路径:

    <filter>
         <filter-name>biosFilter</filter-name>
         <filter-class>com.fix.ciss.login.BiosFilter</filter-class>
    </filter>
    <filter-mapping>
         <filter-name>biosFilter</filter-name>
         <url-pattern>/ReportEmitter</url-pattern>
    </filter-mapping>
    <filter-mapping>
         <filter-name>biosFilter</filter-name>
         <url-pattern>/bios/*</url-pattern>
    </filter-mapping>

 
 


你可能感兴趣的:(Filter拦截跳出FrameSet)