utf-8編碼基礎

package com.luojin.web.filter;java


import java.io.IOException;web


import javax.servlet.Filter;app

import javax.servlet.FilterChain;ide

import javax.servlet.FilterConfig;字體

import javax.servlet.ServletException;url

import javax.servlet.ServletRequest;spa

import javax.servlet.ServletResponse;utf-8


public class FilterOne implements Filter{get

   String  encoding;servlet

//要消耗了

public void destroy() {

}


@Override

public void doFilter(ServletRequest req, ServletResponse resp,

FilterChain chain) throws IOException, ServletException {

req.setCharacterEncoding(encoding);

resp.setCharacterEncoding(encoding);

chain.doFilter(req, resp);

}


//在響應前調用

public void init(FilterConfig config) throws ServletException {

encoding =config.getInitParameter("encoding");

}


}

<!--設置全局過濾字體  -->
    <filter-name>interceptionEncod</filter-name>
   <filter-class>com.luojin.web.filter.FilterOne</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>utf-8</param-value>
 </init-param>
  </filter>
  <filter-mapping>
<filter-name>interceptionEncod</filter-name>
<url-pattern>/*</url-pattern>
 </filter-mapping>
model service dao
相關文章
相關標籤/搜索