重音字母和其他语言,如汉语和阿拉伯语是棘手。
我想你还没有看到这个问题的最后一个。
您应该确保您的文本在链中的任何链接上保持正确编码。
E.g.
- 数据库 - >的java - >响应 - >浏览器
- 属性文件 - > jav->响应 - >浏览器
- 请求(PARAM /表格) - >响应 - >浏览器
- 的java - > logger->控制台
我建议您按照这个伟大的答案 How to get UTF-8 working in Java webapps?
要调整它SPRI ng使用spring的CharacterEncodingFilter。
<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>
如果您使用的国际化确保例如定义的默认编码为您ResourceBundleMessageSource会
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<property name="basename" value="classpath:messages"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="useCodeAsDefaultMessage" value="false"/>
</bean>
确保您的属性文件使用Java的native2ascii正确编码。
或者,如果你使用Eclipse,我建议Property Editor plugin.
有时第三方框架打破东西,你需要做的“神奇”
new String(yourstring, "UTF8")
欲了解更多信息,请参阅here
注意更好一些视图解析器还需要定义编码。
你可能会得到正确的字符,除了它只是当你打印到控制台时,你的控制台不支持utf-8?试试这个:http://stackoverflow.com/questions/2038733/how-do-i-change-a-shell-scripts-character-encoding – gerrytan 2013-02-19 03:38:00
这是一篇文章或获取请求?你可以添加实际的方法与实际的注释? – 2013-02-19 07:37:12
它是Post请求,代码是: RequestMapping(value =“/ userSignup”,method = RequestMethod。POST) \t public String userSignup(\t RequestParam(“name”)String name,RequestParam(“email”)String email,RequestParam(“birthdayDay”)String birthdayDay,RequestParam(“birthdayMonth”)String birthdayMonth,RequestParam(“birthdayYear” )字符串birthdayYear,RequestParam(“性别”)字符串性,RequestParam(“密码”)字符串密码,RequestParam(“passwordConfirmation”)字符串passwordConfirmation,HttpServletResponse响应,ModelMap模型){ – 2013-02-20 01:38:53