1 回答

TA貢獻1820條經(jīng)驗 獲得超3個贊
@RequestBody 既然使用到這個注解,那就說明樓主使用的不是get方法。參數(shù)不在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參數(shù)造成影響。
樓主仔細看一下CharacterEncodingFilter執(zhí)行的過程,以及Filter執(zhí)行的先后順序。
添加回答
舉報