struts、spring国际化资源文件使用简介
来源:互联网 发布:安卓聊天软件编程 编辑:程序博客网 时间:2024/05/29 09:36
前面记录了关于Java API来配置有使用国际化(i18n)的操作,这里将自己了解到的国际化操作在实际应用中的情况记录下来……
(一)、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 StrutsFirsterror.info = \u8f93\u5165\u7684\u4fe1\u606f\u4e0d\u80fd\u4e3a\u7a7a\uff01msg.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);}
更多使用及配置还在学习之中……
- struts、spring国际化资源文件使用简介
- 4.struts国际化:资源文件
- Struts国际化资源文件中文转码
- Struts国际化资源文件中文转码
- Struts 2 国际化与资源文件
- struts 国际化:资源文件访问顺序
- struts中国际化之读取资源文件
- 使用spring实现资源国际化
- java国际化资源文件使用
- Spring MVC 1 资源文件 国际化
- 【Spring】[bug]国际化资源文件找不到 NoSuchMessageException
- Velocity中使用Struts的国际化文件
- Velocity中使用Struts的国际化文件
- struts 2.0 国际化寻找资源文件的顺序
- struts国际化问题,利用Eclipse插件编辑中文资源文件
- struts资源文件的使用
- struts资源文件的使用
- 使用资源文件实现java的国际化
- tftp的access violation问题
- Python 字符编码判断
- Struts的FormFile与Commons-FileUpload控件使用心得
- 从字符串中剥离无效字符
- cocos2d-x 主机游戏
- struts、spring国际化资源文件使用简介
- 路由器相关开发流程
- string和array的某些方法应用
- Jmeter DO NOT support windows authentication on sharepoint
- OOP 详解
- C语言字符串,字符转数字,数字转字符
- cv文档目录
- Git简单的安装与使用
- opencv for python 之 模板匹配