2

我有一些与 Spring MVC 控制器中的绑定 (@ModelAttribute("name") String name)

@RequestMapping(value = "/authors", method = RequestMethod.POST)
public String index(
        @ModelAttribute("name") String name) {...}

Post auf .../authors 表格数据:name=Näöüme

在控制器名称:Näöüme

如果我收到请求输入流,则 name=N%C3%A4%C3%B6%C3%BCme 是 URLEncoded。

有没有办法设置urlencoding?

4

1 回答 1

2

我找到了解决方案,我必须在 web.xml 中设置 filterEncoding:

 <filter>
    <filter-name>encodingFilter</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>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
于 2016-05-10T13:28:32.263 回答