zoukankan      html  css  js  c++  java
  • 第一次使用过滤器

    <filter>
      <filter-name>过滤器的名字</filter-name>
      <filter-class>   
       过滤器的路径(servlet)
      </filter-class>

    <init—param>  

      <param—name>RejectedlP</param-name>//过滤器初始化参数名RejectedlP  

      <param-value>192.168.12.*/param-value>  

    </init—pamm> 
     </filter>
     <filter-mapping>
      <filter-name>必须和上面的过滤器名字一致</filter-name>
      <url-patter>/course.htm</url-pattern><!-- 访问哪些页面或者跳转的文件 -->
     </filter-mapping>

    public class CourseCheckFilter implements Filter {  

    private Logger log=Logger.getLogger(this.getClass());

     public void destroy()  {  }

     @Override

    public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
      HttpServletResponse res=(HttpServletResponse)response;
      HttpServletRequest req=(HttpServletRequest)request;
      if(req.getRequestURI().endsWith("course.htm")==false)//只对course.htm文件过滤
      {
       chain.doFilter(request,response);//通过不处理
       return;
      }
      String requestURL=req.getRequestURL().toString();
      String strParam=req.getQueryString();
      if(strParam!=null&&strParam.length()>0)
      {
       requestURL=requestURL+"?"+strParam;
      }
      String SSO_URL="warn.htm?"+strParam
      if(check(req,res)==false)
      {
       res.sendRedirect(SSO_URL);;//跳转到course.htm时不符合条件是跳转到该路径
       return;
      }
      chain.doFilter(request,response);  //通过不处理
     }

    }

  • 相关阅读:
    iou与giou对比
    Linux学习第一天 vim
    奖励加分申请
    人月神话阅读笔记3
    5.27
    5.26
    5.25
    5.23
    5.22
    5.21
  • 原文地址:https://www.cnblogs.com/qiyongliang/p/3642948.html
Copyright © 2011-2022 走看看