spring3 MVC国际化支持之中文乱码

最近时间在研究spring3的mvc编程。话不多说,直接上代码:
一、页面编码统一采用utf-8(拥抱国际标准)
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>

二、过滤器编码也为utf-8
<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>

三、甚至连.properties的编码方式都改成了utf-8:
[img]http://dl.iteye.com/upload/picture/pic/65987/0c0c4c51-7f76-3dd5-a1db-025fc172c995.jpg[/img]

[color=red]设置完成,但页面显示为乱码。[/color]
后来分析了一下源码:增加了"defaultEncoding"属性为"UTF-8":
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages/messages" />
<property name="cacheSeconds" value="0" />
<property name="defaultEncoding" value="UTF-8"></property></bean>

利用utf-8显示中文问题终于解决了.
注:受struts影响,还使用了native2ascii工具转换编码,还是不行。google,baidu了很久都没找到解决方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值