zoukankan      html  css  js  c++  java
  • filter 过滤emoji

    拦截器
    public class EmojiFilter implements Filter {
    
        private FilterConfig filterConfig;
    
        public void init(FilterConfig filterConfig) throws ServletException {
            System.out.println("Filter initialized");
            this.filterConfig = filterConfig;
        }
    
        public void destroy() {
            System.out.println("Filter destroyed");
            this.filterConfig = null;
        }
    
        public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain chain) throws IOException, ServletException {
            chain.doFilter(new MyRequestWrapper((HttpServletRequest) request), response);
        }
    
    }
    web.xml配置
    <!-- emoji过滤 -->
        <filter>
            <filter-name>EmojiFilter</filter-name>
            <filter-class>com.qtkj.base.EmojiFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>EmojiFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
     1 实际过滤方法
     2 public class MyRequestWrapper extends HttpServletRequestWrapper {
     3     public MyRequestWrapper(HttpServletRequest servletRequest) {
     4         super(servletRequest);
     5     }
     6 
     7     public String[] getParameterValues(String parameter) {
     8         String[] results = super.getParameterValues(parameter);
     9         if (results == null)
    10             return null;        
    11 
    12         int count = results.length;
    13         String[] trimResults = new String[count];
    14         for (int i = 0; i < count; i++) {            
    15             trimResults[i] = com.qtkj.weixin.utils.EmojiFilter.filterEmoji(results[i].trim());
    16             trimResults[i]=trimResults[i].replace(" ", "");
    17         }        
    18         System.out.println("==========="+trimResults+"----------");
    19         return trimResults;
    20     }           
    21 }
    22 结合emoji处理方法中的方法
  • 相关阅读:
    wxPython跨线程调用
    安卓开发24:FrameLayout布局
    URAL 1081
    [置顶] Hibernate运行机理
    [置顶] Hibernate的一个经典异常
    poj1190 生日蛋糕 dfs
    [置顶] 自己写代码生成器之生成Dal层代码(获取数据库所有表名称)
    修改mysql数据存储的地址
    拖延心理学
    DeepLearnToolbox使用总结
  • 原文地址:https://www.cnblogs.com/-lpf/p/5654199.html
Copyright © 2011-2022 走看看