1. 在ApplicationContext 中定义messageSource
其中basenames就是指定的多国语言properties 文件前缀format.properties 这些文件在classpath即可,可以在WEB-INF的classes目录下,也可以打在jar包中放在WEB-INF/lib下
2. 编辑properties 文件,推荐eclipse的rbe插件
3. 在java程序中使用多国语言
通常的做法是把MessageSource 直接注入到bean中,具体参考spring
4. jsp中使用多国语言
3.0中spring拆分了多个包spring.tld文件包含在org.springframework.web.servlet-3.0.X.RELEASE.jar中,web项目要包含此jar否则tld报错
然后在jsp中引入标签库
jsp文件中通过
来引用对应的message
<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