[英]spring roo/spring mvc: how can i set uriencoding for controller method
i have a spring roo webapplication running in tomcat 7. there i have a spring roo generated controller method, that i pushed in for debugging issues: 我有一个在tomcat 7中运行的spring roo webapplication。我有一个spring roo生成的控制器方法,我推进调试问题:
@RequestMapping(params = "find=ByFirstNameEqualsAndLastNameEquals", method = RequestMethod.GET)
public String findAuthorsByFirstNameEqualsAndLastNameEquals(
@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size,
@RequestParam(value = "sortFieldName", required = false) String sortFieldName,
@RequestParam(value = "sortOrder", required = false) String sortOrder,
Model uiModel
) {
System.out.println("find author lastname: " + lastName);
String lastNameUTF8 = null;
String firstNameUTF8 = null;
try {
lastNameUTF8 = new String(lastName.getBytes("ISO-8859-1"), "UTF-8");
System.out.println("lastnameUTF8: " + lastNameUTF8);
firstNameUTF8 = new String(firstName.getBytes("ISO-8859-1"),
"UTF-8");
System.out.println("lastnameISOtoUTF8: " + firstNameUTF8);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
...
as one can see at the logs: 正如人们可以在日志中看到的那样:
find author lastname: ШÑ<U+0082>Ñ<U+0080>ембеÑ<U+0080>г
lastnameISOtoUTF8: Штремберг
the requestparameters firstName and lastName come in encoded as ISO-8859-1, but i expected them UTF-8 encoded. requestparameters firstName和lastName编码为ISO-8859-1,但我希望它们是UTF-8编码的。 i think i saw most of similar questions
我想我看到了大多数类似的问题
and made sure to have all the confurations set to UTF-8: 并确保将所有配置设置为UTF-8:
web.xml: web.xml中:
<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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
tomcats server.xml: tomcats server.xml:
...
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
...
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
URIEncoder="UTF-8"
/>
java arguments: java参数:
/usr/local/jdk7/bin/java -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8 /usr/local/tomcatODM_TEST/bin/bootstrap.jar:/usr/local/tomcatODM_TEST/bin/tomcat ... org.apache.catalina.startup.Bootstrap start
also browser encoding is set to UTF-8, system LANG on server and client: 浏览器编码也设置为UTF-8,服务器和客户端上的系统LANG:
$ echo $LANG en_US.utf8
i don't have any clue what else to do to get rid of that funny ISO-8859-1 decoding of spring mvc i guess... any ideas? 我不知道还有什么可以摆脱那个有趣的ISO-8859-1解码的春天mvc我猜...任何想法? what am i overlooking?
我在俯瞰什么?
I had the same issue and after much research realised it was the Tomcat connector which was the issue. 我有同样的问题,经过大量研究后发现Tomcat连接器是问题所在。 I tried everything but only adding the following fixed it to the "server.xml"
我尝试了一切但只添加以下内容将其修复为“server.xml”
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
It's annoying that you can't set something in Spring to set the URIEncoding. 令人讨厌的是你无法在Spring中设置一些东西来设置URIEncoding。
Also, initially the <connector ... URIEncoding="UTF-8"/>
update didn't work but it was because my Tomcat "server.xml" was being overriden so make sure that isn't the case. 此外,最初
<connector ... URIEncoding="UTF-8"/>
更新不起作用,但这是因为我的Tomcat“server.xml”被覆盖,所以请确保不是这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.