81,114
社区成员
发帖
与我相关
我的任务
分享
package com.dz.filter;
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;
/**
* 编码过滤器实体类
* @author Administrator
*
*/
public class EncodingFilter implements Filter {
private FilterConfig config;
private String encoding="utf-8";
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);//继续过滤
}
public void init(FilterConfig config) throws ServletException {
this.config=config;
String s=config.getInitParameter("encoding");//获取初始化参数数,
if(s!=null){
this.encoding=s;
}
}
}
<%
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
response.setContentType("text/html";charset="gb2312");
%>