1 回答

TA贡献1820条经验 获得超2个赞
@RequestBody 既然使用到这个注解,那就说明楼主使用的不是get方法。参数不在URL中那自然是不需要使用URLEncoding.encode的吧。
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
你这里设置了编码就足够了。
@Override
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);
}
forceEncoding 为 true 为设置response的编码,并不会对request参数造成影响。
楼主仔细看一下CharacterEncodingFilter执行的过程,以及Filter执行的先后顺序。
添加回答
举报