当前位置:编程学习 > JAVA >>

public void doFilter(ServletRequest request, ServletResponse response,

AutoLoginFilterpackage com.itheima.tfy.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;
//解决全站中文乱码问题
//缺点:只对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;
}
 
 
}
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,