用过滤器实现,如果SESSION失效,界面弹回到包含框架的父框架中

public void doFilter(ServletRequest request, ServletResponse response,
   FilterChain chain) throws IOException, ServletException {
  HttpServletRequest hreq = (HttpServletRequest)request;
  HttpServletResponse hres = (HttpServletResponse)response;
  String result = "/Kindergarden/starsheaven37/login.jsp";
 
  RequestDispatcher rd = null;
  String errormessage= config.getInitParameter("errormessage");
  HttpSession session = hreq.getSession(); 
   if (session.getAttribute("PerName") == null) {
    rd = hreq.getRequestDispatcher(result);
    request.setAttribute("errormessage",errormessage);
    //System.out.println("UserFilter 过滤器中");
    //System.out.println("对不起您还没登陆,请您先登陆!");
    //hres.sendRedirect(result);
    //rd.forward(request, response);

 //如果采取FORWARD或者是sendRedirect的方法,只能跳转到子窗口中
    PrintWriter out = hres.getWriter();
    out.println("<script type='text/javascript'>window.parent.location='"+result+"'</script>");
   }
   else
   {
    chain.doFilter(request, response);
   }
 }

你可能感兴趣的:(JavaScript,框架,jsp)