spring国际化的使用
来源:互联网 发布:淘宝店铺的简介大全 编辑:程序博客网 时间:2024/06/02 11:29
1:在MyEclipse下面创建一个test的Web Project,然后添加Spring相关的文件,在src根目录下创建applicationContext.xml文件。
applicationContext.xml
2:在src根目录下面创建4个资源文件:分别是
3:在WebRoot根目录下面创建test.jsp
test.jsp
4:修改WEB-INF下面的web.xml
在web.xml加入
这样用Spring国际化的Test.jsp页面就做好了:),此种方法是自动默认当前用户的语言,比如客户端是日语系统,就自动寻找messages_ja.properties资源文件,是英语系统,就自动寻找messages_en.properties资源文件。
注意事项:
1:用hibernate3.0,连接Mysql5.0数据库。
如果用hibernate.properties配置文件
hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
如果用hibernate.cfg.xml配置文件
jdbc:mysql://localhost:3306/test?useUnicode=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8
2:页面的编码方式,应该选用utf-8
<%@ page language="java" pageEncoding="UTF-8"%>
3:创建的数据库的编码方式也应该选用utf-8,以及表,字段的编码方式都应选用utf-8
注意以上3点就可以解决国际化时,所出现的页面显示乱码问题,以及插入韩语时,出现的data too long for column问题.
applicationContext.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
- <property name="basename" value="messages"/>
- </bean>
- <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>
- </beans>
2:在src根目录下面创建4个资源文件:分别是
引用
messages_zh.properties
main.title=你好
messages_en.properties
main.title=Hello World!
messages_ja.properties
main.title=こんにちは
messages_ko.properties
main.title=안녕하십니까
main.title=你好
messages_en.properties
main.title=Hello World!
messages_ja.properties
main.title=こんにちは
messages_ko.properties
main.title=안녕하십니까
3:在WebRoot根目录下面创建test.jsp
test.jsp
- <%@ page language="java" pageEncoding="UTF-8"%>
- <%@ taglib prefix="spring" uri="WEB-INF/lib/spring.tld"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Spring国际化</title>
- </head>
- <body>
- <spring:message code="main.title" /><br>
- <input type="button" value="<spring:message code="main.title" />"/><br>
- </body>
- </html>
4:修改WEB-INF下面的web.xml
在web.xml加入
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath*:/applicationContext*,classpath*:META-INF/applicationContext*.xml
- </param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
这样用Spring国际化的Test.jsp页面就做好了:),此种方法是自动默认当前用户的语言,比如客户端是日语系统,就自动寻找messages_ja.properties资源文件,是英语系统,就自动寻找messages_en.properties资源文件。
注意事项:
1:用hibernate3.0,连接Mysql5.0数据库。
如果用hibernate.properties配置文件
hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
如果用hibernate.cfg.xml配置文件
jdbc:mysql://localhost:3306/test?useUnicode=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8
2:页面的编码方式,应该选用utf-8
<%@ page language="java" pageEncoding="UTF-8"%>
3:创建的数据库的编码方式也应该选用utf-8,以及表,字段的编码方式都应选用utf-8
注意以上3点就可以解决国际化时,所出现的页面显示乱码问题,以及插入韩语时,出现的data too long for column问题.
0 0
- spring国际化的使用
- Spring的国际化
- spring的国际化
- Spring的国际化
- Spring的国际化(转载)
- Spring的国际化
- 使用Spring MVC 实现 国际化
- spring国际化方法(使用SessionLocaleResolver)
- java使用spring国际化文字
- 使用spring实现资源国际化
- 使用Spring中的IoC功能来实现系统的国际化
- Spring Applicationcontext的国际化支持
- Spring Applicationcontext的国际化支持
- Spring对国际化的支持
- spring mvc的controller国际化
- Spring中的国际化的处理
- Spring MVC国际化的总结
- Spring ApplicationContext的国际化支持
- 楼市崩盘对中国有利,你觉得呢
- Android通过adb命令与Linux系统连接
- CCAccelerometerDelegate(重力感应消息委托)
- JAVA工厂设计模式
- iperf详细使用方法
- spring国际化的使用
- 锁定表头和固定列(Fixed table head and columns)
- [LeetCode]Reverse Words in a String
- cvFitEllipse
- uml系列资料转载-http://www.cnblogs.com/ywqu/category/223486.html(博客园-灵动生活)
- Cygwin的中文支持(解决乱码)
- 在Qt中连接SQLite和MySQL数据库
- scanf的用法
- .NET通过RFC读取SAP数据