Spring3MVC:Internationlization&Localization Tutorial with Example
来源:互联网 发布:杭州百替生物数据造假 编辑:程序博客网 时间:2024/06/05 21:21
我们将会创建两个properties文件,他们包含显示的所有信息,这些文件被放在叫做resources的目录中,
Right click on Project name > New > Source Folder and name it resources.
创建两个文件:messages_en.properties和messages_de.properties在这个目录中,拷贝下面的代码
File: resources/messages_en.properties
label.firstname=First Name
label.lastname=Last Name
label.email=Email
label.telephone=Telephone
label.addcontact=Add Contact
label.menu=Menu
label.title=Contact Manager
label.footer=© dufeng
label.firstname=Vorname
label.lastname=Familiename
label.email=Email
label.telephone=Telefon
label.addcontact=Addieren Kontakt
label.title=Kontakt Manager
label.menu=Menü
label.footer=© dufeng
File:WebContent/WEB-INF/spring-servlet.xml
<
bean
id
=
"messageSource"
class
=
"org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<
property
name
=
"basename"
value
=
"classpath:messages"
/>
<
property
name
=
"defaultEncoding"
value
=
"UTF-8"
/>
</
bean
>
<
bean
id
=
"localeChangeInterceptor"
class
=
"org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
>
<
property
name
=
"paramName"
value
=
"lang"
/>
</
bean
>
<
bean
id
=
"localeResolver"
class
=
"org.springframework.web.servlet.i18n.CookieLocaleResolver"
>
<
property
name
=
"defaultLocale"
value
=
"en"
/>
</
bean
>
<
bean
id
=
"handlerMapping"
class
=
"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
>
<
property
name
=
"interceptors"
>
<
ref
bean
=
"localeChangeInterceptor"
/>
</
property
>
</
bean
>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<
h3
><
spring:message
code
=
"label.title"
/></
h3
>
<
span
style
=
"float: right"
>
<
a
href
=
"?lang=en"
>en</
a
>
|
<
a
href
=
"?lang=de"
>de</
a
>
</
span
>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<
p
><
spring:message
code
=
"label.menu"
/></
p
>
File:WebContent/WEB-INF/jsp/footer.jsp
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<
spring:message
code
=
"label.footer"
/>
File:WebContent/WEB-INF/jsp/contact.jsp
taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<
html
>
<
head
>
<
title
>Spring 3 MVC Series - Contact Manager</
title
>
</
head
>
<
body
>
<
form:form
method
=
"post"
action
=
"addContact.html"
>
<
table
>
<
tr
>
<
td
><
form:label
path
=
"firstname"
><
spring:message
code
=
"label.firstname"
/></
form:label
></
td
>
<
td
><
form:input
path
=
"firstname"
/></
td
>
</
tr
>
<
tr
>
<
td
><
form:label
path
=
"lastname"
><
spring:message
code
=
"label.lastname"
/></
form:label
></
td
>
<
td
><
form:input
path
=
"lastname"
/></
td
>
</
tr
>
<
tr
>
<
td
><
form:label
path
=
"lastname"
><
spring:message
code
=
"label.email"
/></
form:label
></
td
>
<
td
><
form:input
path
=
"email"
/></
td
>
</
tr
>
<
tr
>
<
td
><
form:label
path
=
"lastname"
><
spring:message
code
=
"label.telephone"
/></
form:label
></
td
>
<
td
><
form:input
path
=
"telephone"
/></
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>
<
input
type
=
"submit"
value
=
"<spring:message code="
label.addcontact"/>"/>
</
td
>
</
tr
>
</
table
>
</
form:form
>
</
body
>
</
html
>
- Spring3MVC:Internationlization&Localization Tutorial with Example
- Spring3MVC:Themes in Spring-Tutorial with Example
- Spring3MVC:tiles plugin Tutorial with Example in Eclipse
- Oracle XMLTable Tutorial With Example
- Struts 2 Ajax Tutorial with Example
- FreeMarker(FTL) Hello World Tutorial with Example
- Spring MVC with ParameterizableViewController Tutorial and Example
- Grails with ATS Transformation tutorial with a demo example
- Struts 2 File Upload and Save Tutorial with Example
- JSP Custom tags with example – JSP Tutorial
- Android Localization Tutorial (Android 本地化)
- A Simple Localization Example for the iPhone
- Struts 2 – i18n or localization example
- Tutorial: DTrace by Example
- CGICC:A Tutorial Example
- ANDROID STAGGEREDGRIDLAYOUTMANAGER EXAMPLE TUTORIAL
- Create Spring3MVC Hibernate3 Example using Maven in Eclipse
- Java debugging tutorial - 10 tips on debugging in java with example
- iphone 给应用添加url URL scheme
- JAVA自带的MD5转换
- 内存分配管理(一)
- STM32嵌入式开发"warning: last line of file ends without a newline"解决方法
- 核心控制器ActionServlet的工作流程
- Spring3MVC:Internationlization&Localization Tutorial with Example
- 深入理解JavaScript中的this关键字
- 阿里巴巴笔试题
- 对文件操作seek时报错“can't do nonzero end-relative seeks”
- 我们都一样
- Wine乱码
- Java身份证格式验证类--封装类
- mysql集群安装、配置
- 使用Android Lint Checks使你的android应用更健壮