利用Filter解决Post请求中文乱码
一、创建一个拦截所有请求的拦截器
@WebFilter(filterName = "login",
dispatcherTypes = DispatcherType.REQUEST,
urlPatterns = {"/*"})
public class LoginFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
}
@Override
public void destroy() {
}
}
二、进行统一响应编码处理
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletResponse.setCharacterEncoding("UTF-8");
}
我好凶的
发布了8 篇原创文章 · 获赞 0 · 访问量 70
私信
关注