我有个网页,要求过滤一部份IP,过滤中的IP也不是都不能访问,如果用密码也可以访问。我在过滤器中这样设置:
  String ip=request.getRemoteHost();
        int pos=ip.lastIndexOf(".");
        ip=ip.substring(0, pos);
        if(ip.equals("192.168.1"))
        {
         resp.getWriter().print("您的ip被禁止访问本站");
         resp.sendRedirect("/hecny/login2.jsp");
         return;
        }
       
        else
        {
                chain.doFilter(request, response);
        }
web.xml中这样配的:
 <filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
过滤所有根目录下的请求,我的目的是被过滤掉的IP可通过login2.jsp输入用户名,密码来登陆网站。可我这是个死循序,不断的刷新login2.jsp,请高手指点。

解决方案 »

  1.   

    你要通过login2.jsp来输入密码的话,你发送到/hecny这个路径。。但是这个路径却你在/* 过滤的范围之内,又判断是否是那个IP。。然后再发,再过滤所以就死循环了呗。。
      

  2.   

    问题跟楼上说的一样,要解决这个问题,就是你在他通过login2.jsp输入用户名,密码来登陆网站后,要系统知道他通过了验证,所以需要做一个标志位,例如boolean check=true,在判断的时候判断是否经过了验证,如果是就放行。 if(ip.equals("192.168.1") || check){} 
      

  3.   

     String ip=request.getRemoteHost(); 
            int pos=ip.lastIndexOf("."); 
            ip=ip.substring(0, pos); 
            if(ip.equals("192.168.1")) 
            { //说明这是要被过滤的网站
                boolean b = isLogin();//用来判断它是否登陆
                if(!b)
                resp.getWriter().print("您的ip被禁止访问本站"); 
                resp.sendRedirect("/hecny/login2.jsp"); 
              }
             return; 
            }      
            else 
            { 
                    chain.doFilter(request, response); 
            }