繁体   English   中英

Spring Web MVC :: GET方法:: RequestParam编码

[英]Spring Web MVC :: GET method :: RequestParam encoding

我有一个REST入口点:

@RequestMapping(value = "user" method = RequestMethod.GET)
public List<User> getUsers( @RequestParam(value = "name") String name )

我正在使用AngularJS发送/rest/user?name=Иван ,并且请求在rest/user?name=%D0%98%D0%B2%D0%B0%D0%BD中使用urlencode编码。

但是该方法以ISO_8859_1字符集接收name ,而不是像预期的那样以UTF-8接收name 如果我写

new String(request.getName().getBytes( StandardCharsets.ISO_8859_1 ), StandardCharsets.UTF_8)

变得很好。 但这不是正确的方法:)

我在做什么错以及如何解决?

===

聚苯乙烯

在我的web.xml中,我已经为UTF-8编码配置了CharacterEncodingFilter

<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>

您是否使用gradle构建项目? 在构建时,请尝试使用-Dfile.encoding = utf-8标志,默认编码是系统编码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM