简体   繁体   English

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

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

I've got a REST entrypoint: 我有一个REST入口点:

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

I'm sending there /rest/user?name=Иван using AngularJS, and the request is encoded with urlencode in rest/user?name=%D0%98%D0%B2%D0%B0%D0%BD . 我正在使用AngularJS发送/rest/user?name=Иван ,并且请求在rest/user?name=%D0%98%D0%B2%D0%B0%D0%BD中使用urlencode编码。

But the method receives name in ISO_8859_1 charset, not in UTF-8 like expected. 但是该方法以ISO_8859_1字符集接收name ,而不是像预期的那样以UTF-8接收name If I write 如果我写

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

it becomes fine. 变得很好。 But this is not a correct way :) 但这不是正确的方法:)

What am I doing wrong and how to fix it? 我在做什么错以及如何解决?

=== ===

PS 聚苯乙烯

In my web.xml I've got a CharacterEncodingFilter configurated for UTF-8 encoding 在我的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>

Do you build your project with gradle? 您是否使用gradle构建项目? Try the flag -Dfile.encoding=utf-8 when you build, the default encoding is the system one 在构建时,请尝试使用-Dfile.encoding = utf-8标志,默认编码是系统编码

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

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