1.SpringMVC的配置(廢話一下。在web.xml)
?1
?<listener>
?2
???????<listener-class>
?3
????????????org.springframework.web.context.ContextLoaderListener
?4
???????</listener-class>
?5
????</listener>
?6
?7
????<init-param>
?8
?????????<param-name>responseHeadersSetBeforeDoFilter</param-name>
?9
?????????<param-value>true</param-value>
10
????</init-param>
11
12
?????<context-param>
13
?????????<param-name>contextConfigLocation</param-name>
14
?????????<param-value>
15
?????????????classpath*:context/applicationContext-db.xml?/WEB-INF/XXX-servlet.xml
16
?????????</param-value>
17
?????</context-param>
18
? 說明:不用了吧,這是配置SpringMVC的基礎(chǔ)。
?2

?3

?4

?5

?6

?7

?8

?9

10

11

12

13

14

15

16

17

18

2.在XXX-servlet.xml中添加:
?1??<!--?語言國(guó)際化?-->
?2??<bean
?3????????class="org.springframework.context.support.ResourceBundleMessageSource"
?4????????id="messageSource">
?5???<property?name="basenames">
?6?
?7?<!--??value="/WEB-INF/config/"?指定message存放的位置?-->
?8????<list>
?9???????<value>message</value>
10????</list>
11????</property>
12??</bean>
13?
14?
?2??<bean
?3????????class="org.springframework.context.support.ResourceBundleMessageSource"
?4????????id="messageSource">
?5???<property?name="basenames">
?6?
?7?<!--??value="/WEB-INF/config/"?指定message存放的位置?-->
?8????<list>
?9???????<value>message</value>
10????</list>
11????</property>
12??</bean>
13?
14?
說明:很簡(jiǎn)單,spring中提供了一個(gè)ResourceBundle的類。配置這個(gè)類:<property name="basenames" value="/WEB-INF/config/">中的basenames指的是名字.properties文件的前綴。當(dāng)使用國(guó)際化語言的話.properties文件的命名是basenames指定的基本名字。如果中文的話,.properties為message_cn_**.properties什么的,忘記了。根據(jù)你的瀏覽器設(shè)置的。可以打印一下,自己看看(java.util.Locale)。value="/WEB-INF/config/" 指定.properties文件存放的位置。
3.前臺(tái)顯示
? 使用<spring:message code=""/>這個(gè)標(biāo)簽。別忘了在jsp頁(yè)面的頭加上<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>這個(gè)。
其實(shí),官方文檔寫的相當(dāng)?shù)脑敿?xì)。至于網(wǎng)上其他的例子,我沒做通過。只好看官方文檔了。比較郁悶啊~很簡(jiǎn)單的東西,研究了將近3個(gè)多小時(shí)。
OK了,enjoy it。