0
我已經有了一個REST入口點:Spring Web MVC框架:: GET方法:: RequestParam編碼
@RequestMapping(value = "user" method = RequestMethod.GET)
public List<User> getUsers(@RequestParam(value = "name") String name)
我送有/rest/user?name=Иван
使用AngularJS,並請求在rest/user?name=%D0%98%D0%B2%D0%B0%D0%BD
編碼與urlencode
。
但該方法在ISO_8859_1
字符集中收到name
,而不是像預期的那樣在UTF-8中。 如果我寫
new String(request.getName().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)
它會好起來的。但這不是一個正確的方法:)
我在做什麼錯誤,以及如何解決它?
===
P. S.
在我的web.xml我有可配置爲UTF-8
編碼
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
我使用maven,並且在maven-compiler-plugin屬性中使用' UTF-8 '。我的所有文件也都是UTF-8。 –
omickron
好吧,那麼嘗試添加 ' forceEncoding 真正的參數值> ' 到您的過濾器設置 –
但我不需要forceEncoding - 它將設置響應編碼,然後,但問題是關於請求。查看來源https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java#L194 – omickron