Spring mvc 国际化支持已经UTF-8中文乱码问题的解决方案

1、在SPRING的配置文件中添加国际化支持:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="/WEB-INF/classes/messages"/>
        <property name="cacheSeconds" value="0" />
        <property name="defaultEncoding" value="UTF-8"/>
</bean>

defaultEncoding value utf-8可以解决乱码文件,

2、在src下新建配置文件:
messages.properties messages_cn_ZH.properties messages_en_US.properties 等等。。

3、在JSP中调用

<spring:message code="projectname" />

关于Zeno Chen

本人涉及的领域较多,杂而不精 程序设计语言: Perl, Java, PHP, Python; 数据库系统: MySQL,Oracle; 偶尔做做电路板的开发,主攻STM32单片机
此条目发表在Java分类目录。将固定链接加入收藏夹。