过滤器设置编码

util包中:

      添加类 CharacterEncodingFilter implementsFilter

        destroy方法

doFilter方法中:

// 转换为HttpServletRequest

HttpServletRequest request = (HttpServletRequest) req; // 强转

response = (HttpServletRequest) res;

// 设置字符编码

request.setCharacterEncoding(“UTF-8”);

response.setCharacterEncoding

// 请求继续执行

fChain.doFilter(request, response);

init方法


       配置:(要过滤什么请求呢)

      

      

              filter-name

      

              url-pattern/*

<filter>

   <filter-name>characterEncodingfilter-name>

   <filter-class>com.icss.util.CharacterEncodingFilterfilter-class>

 filter>

 <filter-mapping>

   <filter-name>characterEncodingfilter-name>

   <url-pattern>/*url-pattern>

  filter-mapping>

   action等使用post方法,上述编码过滤器才会生效。


你可能感兴趣的:(Java,EE)