我正在看看Spring MVC提供的CharacterEncodingFilter。我想知道爲什麼只有在請求編碼被強制爲給定編碼時才能設置響應編碼?如果accept頭域中沒有指定任何內容,爲什麼不能設置默認的響應編碼?或者如果請求中沒有編碼?Spring MVC:CharacterEncodingFilter;爲什麼只強制設置響應編碼?
的代碼:
@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);
}
我發現這個作爲參考 https://jira.springsource.org/browse/SPR-3328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel 指出的是,當請求編碼被強制設置響應編碼只能設置。爲什麼?
由於提前, 馬丁
可能它與http://stackoverflow.com/questions/3616359/who-sets-response-content-type相關-in-spring-mvc-responsebody(如果我沒有丟失東西) – 2012-07-27 10:10:48