zoukankan      html  css  js  c++  java
  • Web.xml配置----字符过滤器

    添加EncodingFilter类实现Filter接口

    import javax.servlet.*;
    import javax.servlet.http.HttpServletRequest;
    import java.io.IOException;

    public class EncodingFilter implements Filter {
        FilterConfig config = null;
        // default to GBK
        private String targetEncoding = "GBK";

        public void init(FilterConfig config) throws ServletException {
            this.config = config;
            this.targetEncoding = config.getInitParameter("encoding");
        }

        public void destroy() {
            config = null;
            targetEncoding = null;
        }

        public void doFilter(ServletRequest srequest, ServletResponse sresponse,
                             FilterChain chain) throws IOException, ServletException {

            HttpServletRequest request = (HttpServletRequest)srequest;
            request.setCharacterEncoding(targetEncoding);
            chain.doFilter(srequest, sresponse);
        }
    }

    在配置在web.xml中添加
        <filter>
            <filter-name>encodingFilter</filter-name>
            <filter-class>xx.xx.xx.EncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                <param-name>useragents</param-name>
                <param-value>Mac</param-value>
            </init-param>
        </filter>

        <filter-mapping>
            <filter-name>encodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

  • 相关阅读:
    伪元素改变placeholder占位符属性的默认样式实例页面
    盒子中margin重叠问题
    html或CSS的图片如何随着网页界面的缩小或放大跟着左右移动 ?
    相对路径与绝对路径
    Html5 Canvas小知识
    dl,dt,dd怎么用
    雪碧图
    linux--mysql图形工具 tora
    apt-get彻底卸载删除软件http://www.tennfy.com/1518.html
    【转】 httpclient 模拟浏览器动作需注意的cookie和HTTP头等信息
  • 原文地址:https://www.cnblogs.com/lpwbk/p/5580553.html
Copyright © 2011-2022 走看看