标签:void stat rac ini 设置 exception Servle text coding
import javax.servlet.*;
import java.io.IOException;
public class CharacterEncodingFilter implements Filter {
private static String encoding; // 定义变量接收初始化的值
@Override
public void init(FilterConfig config) throws ServletException {
encoding = "UTF-8";
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
// 导致css加载不生效
// response.setContentType("text/html;charset="+encoding); //设置response字符编码
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}
标签:void stat rac ini 设置 exception Servle text coding
原文地址:https://www.cnblogs.com/pipilong/p/14356765.html