Spring 3.0 Applicationcontext的国际化支持

1. 在ApplicationContext 中定义messageSource
<beans>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>format</value>
<value>exceptions</value>
<value>windows</value>
</list>
</property>
</bean>
</beans>

其中basenames就是指定的多国语言properties 文件前缀format.properties 这些文件在classpath即可,可以在WEB-INF的classes目录下,也可以打在jar包中放在WEB-INF/lib下

2. 编辑properties 文件,推荐eclipse的rbe插件

3. 在java程序中使用多国语言
public static void main(String[] args) {
MessageSource resources = new ClassPathXmlApplicationContext("beans.xml");
String message = resources.getMessage("message", null, "Default", null);
System.out.println(message);
}

通常的做法是把MessageSource 直接注入到bean中,具体参考spring

4. jsp中使用多国语言
3.0中spring拆分了多个包spring.tld文件包含在org.springframework.web.servlet-3.0.X.RELEASE.jar中,web项目要包含此jar否则tld报错
然后在jsp中引入标签库
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

jsp文件中通过
<spring:message code="system.login.error " />

来引用对应的message
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值