不少时候,咱们觉得配置了CharacterEncodingFilter就能解决乱码问题,实际上不是的,java
咱们能够观察其doFilterInternal方法this
protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) { request.setCharacterEncoding(this.encoding); if (this.forceEncoding) { //这里只设置了编码字符 response.setCharacterEncoding(this.encoding); } } filterChain.doFilter(request, response); }
响应的话还须要设置内容类型,好比:编码
response.setContentType(MediaType.TEXT_HTML);code