首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 云计算 >

public void doFilter(ServletRequest request, ServletResponse response

2013-01-23 
public void doFilter(ServletRequest request, ServletResponse response,AutoLoginFilterpackage com.it

public void doFilter(ServletRequest request, ServletResponse response,
AutoLoginFilterpackage com.itheima.tfy.filter.simple;


import java.io.IOException;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
//解决全站中文乱码问题
//缺点:只对post有效  没有解决post方式 请求参数的乱码问题
public class CharacterEncodingFilter implements Filter {
     private FilterConfig filterConfig;
public void destroy() {


}


public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String encoding=filterConfig.getInitParameter("encoding");
if(encoding==null){
encoding="UTF-8";
}
response.setCharacterEncoding(encoding);
response.setContentType("text/html;charset="+encoding);

request.setCharacterEncoding(encoding);
chain.doFilter(request, response);



}


public void init(FilterConfig filterConfig) throws ServletException {
   
this.filterConfig=filterConfig;
}


}

热点排行