struts、spring国际化资源文件使用简介
2012-12-14 18:23
465 查看
前面记录了关于Java API来配置有使用国际化(i18n)的操作,这里将自己了解到的国际化操作在实际应用中的情况记录下来……
(一)、struts中的国际化简介:
1、配置struts-config.xml:在
注:以上配置的struts为版本1,在其后加入的message-resourses标记,属性parameter为文件所在的类路径。
2、编写一个简单的资源文件ApplicationResources.properties
3、使用
可在jsp页面通过struts标签:<bean:message key="error.info"/>,或者通过 new ActionMessage("msg.info")将其增加到ActionMessages中,而后Jsp页面有标签
<html:messages id="info" message="true">
${info}
</html:messages>
得到资源文件的值。真正意义上的国际化资源文件在于将一个网站能够支持多国语言显示,比如一个网站提供两个链接选择使用那种语言显示(也可以是自动由浏览器识别)
参考:http://hi.baidu.com/liuzhe041/item/eda404e02b7fb5a4cf2d4fc0
(二)、sping 简单配置及使用
1、配置messagerResources.properties(略)
applicationContext.xml
以上配置直接加到根结点<beans>下
2、使用,可以写一个方法封装
private static ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
更多使用及配置还在学习之中……
(一)、struts中的国际化简介:
1、配置struts-config.xml:在
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="helloForm" type="org.lxh.struts.form.HelloForm" /> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings> <action attribute="helloForm" input="/hello.jsp" name="helloForm" path="/hello" scope="request" type="org.lxh.struts.action.HelloAction"> <forward name="show" path="/hello.jsp"></forward> </action> </action-mappings> <message-resources parameter="org.lxh.struts.ApplicationResources" /> </struts-config>
注:以上配置的struts为版本1,在其后加入的message-resourses标记,属性parameter为文件所在的类路径。
2、编写一个简单的资源文件ApplicationResources.properties
# Resources for parameter 'com.xiaoli.struts.ApplicationResources' # Project StrutsFirst error.info = \u8f93\u5165\u7684\u4fe1\u606f\u4e0d\u80fd\u4e3a\u7a7a\uff01 msg.info = \u60a8\u8f93\u5165\u7684\u6570\u636e\u8fc7\u957f\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01
3、使用
可在jsp页面通过struts标签:<bean:message key="error.info"/>,或者通过 new ActionMessage("msg.info")将其增加到ActionMessages中,而后Jsp页面有标签
<html:messages id="info" message="true">
${info}
</html:messages>
得到资源文件的值。真正意义上的国际化资源文件在于将一个网站能够支持多国语言显示,比如一个网站提供两个链接选择使用那种语言显示(也可以是自动由浏览器识别)
参考:http://hi.baidu.com/liuzhe041/item/eda404e02b7fb5a4cf2d4fc0
(二)、sping 简单配置及使用
1、配置messagerResources.properties(略)
applicationContext.xml
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messagerResources" /> </bean>
以上配置直接加到根结点<beans>下
2、使用,可以写一个方法封装
private static ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
public static String getText(String code, Locale locale,Object... args){ String str = ctx.getMessage(code,args,locale); return str; } /** * * @param code * 国际化代码 * @rOeturn */ public static String getText(String code){ return getText(code, null, null); }
更多使用及配置还在学习之中……
相关文章推荐
- Spring多配置文件与国际化,使用资源文件
- IntelliJ & Spring 设置使用国际化资源文件
- Springboot 使用 JSR 303 对 Controller 控制层校验及 Service 服务层 AOP 校验 使用消息资源文件对消息国际化
- struts中国际化之读取资源文件
- spring和java国际化资源文件加载顺序
- SSH(struts+spring+hibernate)迅速开发--第五章 定义配置和资源文件
- Myeclipse中使用国际化资源文件的插件
- springMVC子容器使用spring父容器配置文件资源
- (下节)Spring+JDBC+Struts;实现图片上传(后台文件名要规范),加国际化;头文件basepath确保路径从webroot开始;
- Spring boot 国际化自动加载资源文件去除默认国际化文件
- struts1.3 资源文件配置和使用
- spring中如何配置国际化资源文件
- AppCode文件夹中的中文不能使用资源文件来国际化
- Velocity中使用Struts的国际化文件
- NET中对资源文件的使用简介
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
- 使用Spring访问资源文件
- 【spring boot】3.spring boot项目,绑定资源文件为bean并使用
- springMVC子容器使用spring父容器配置文件资源
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件