import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@WebFilter("/*")
public class EncodingFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
String uri = request.getRequestURI();
// 可以跳过某些链接
if(uri == null || !uri.contains("ueditor1.4.3")) {
//解决中文乱码问题
servletRequest.setCharacterEncoding("utf-8");
servletResponse.setContentType("text/html;charset=UTF-8");
}
filterChain.doFilter(servletRequest,servletResponse);//为了让程序继续运行,需要添加这句话,否则就会终止
}
@Override
public void destroy() {
}
}
标签:java,javax,filter,import,Override,utf,servletRequest,public
From: https://www.cnblogs.com/LDZZDL/p/17134680.html