我在Spring MVC Controller中有一些绑定(@ModelAttribute(“name”)字符串名称)
@RequestMapping(value = "/authors", method = RequestMethod.POST)
public String index(
@ModelAttribute("name") String name) {...}
发表评论... /作者 表格数据:name =Näöüme
在控制器名称中:Näöüme
如果我收到请求输入流,名称= N%C3%A4%C3%B6%C3%BCme是URLEncoded。
有没有办法设置urlencoding?
答案 0 :(得分:3)
我找到了解决方案,我必须在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>