关于struts标签bean:message(转)
来源:互联网 发布:淘宝猜你喜欢在哪里 编辑:程序博客网 时间:2024/05/22 08:17
bean:message标签用来从指定的locale中取回国际化的消息并输出,在这个过程中我们还可以传递五个以内的参数。message key可以通过key直接指定,也可以通过name和property间接的指定。
bean:message标签有两种指定message key的方式,一是通过key属性直接指定;二是通过name和property属性间接的指定,其中message key是在message resources文件中定义的。
我们可以在struts-config.xml文件中使用<message-resources>来设置message resources文件。
为了介绍该标签我使用了三个message resources文件,三个文件的名字分别为Resources.properties、Resources_en.properties和Resources_zh.properties。在struts-config.xml文件中的设置(这里不用设置三个,struts会依据locale自动找到对应的文件)如下:
<message-resources parameter="Resources" />
三个message resources文件中定义的message key为:
<!-- Resources.properties -->
resource=Resources.properties.
from=Resources.properties.
<!-- Resources_en.properties -->
from=Resources_en.properties.
<!-- Resources_zh.properties
from=Resources_zh.properties.
下面的代码片段示例了bean:message标签的用法:
<bean:message key="from"/><br/>
<bean:message key="resource"/><br/>
<html:link action="/locale?language=en">English</html:link>
<html:link action="/locale?language=zh">Chinese</html:link>
上面的代码中含有改变locale的两个html:link标签,要使它们工作您的struts-config.xml文件中必须含有下面定义的form和action:
<form-bean name="localeForm"
type="org.apache.struts.action.DynaActionForm">
<form-property name="language" type="java.lang.String" />
<form-property name="country" type="java.lang.String" />
<!--action成功后要跳到那里-->
<form-property name="page" type="java.lang.String"
initial="/message.jsp"/>
</form-bean>
<action path="/locale" type="org.apache.struts.actions.LocaleAction"
name="localeForm" scope="request">
</action>
在不同的locale下我们得到了如下的两个结果:
在locale为zh时的结果:
Resources_zh.properties.
Resources.properties.
在locale为en时的结果:
Resources_en.properties.
Resources.properties.
让我们来看一下在locale为zh时如何得到的是上面的结果。因为locale为zh所以<bean:message key="from"/><br/>先找Resources_zh.properties这个文件从中得到form键的值。而<bean:message key="resource"/><br/>也会先找Resources_zh.properties这个文件但这次没有找到resource键,这时Struts会到Resources.properties这个文件中找,很幸运这里找到了。如果还没有找到,或message resource文件不存在就会抛出异常。当locale为en时类似,可以自己试试。
- 关于struts标签bean:message(转)
- 关于struts标签bean:message(转)
- 关于struts标签bean:message(转)
- 关于struts标签bean:message
- Struts源码研究 - Bean-Message标签
- Struts源码研究 - Bean-Message标签篇
- Struts源码研究-Bean-Message标签篇
- Struts源码研究 - Bean-Message标签篇
- Struts源码研究 - Bean-Message标签篇
- struts的bean标签使用message
- Struts源码研究 - Bean-Message标签篇[转载]
- struts中的bean-message标签用来实现国际化
- Bean:message标签
- <bean:message>标签
- Struts标签(2)Bean标签
- struts标签:bean标签
- Struts标签-BEAN标签
- struts标签---bean标签
- 问问
- 系统从MySQL移植到Oracle的一些简单总结
- 查看调试信息
- 一根还是两根?AP天线和信号分析
- 将C++文件做成LIB库文件
- 关于struts标签bean:message(转)
- 我是一个极其讨厌av和看av的人
- DELETE和TRUNCATE
- dropdownlist 绑定
- linux下mysql 安装 笔记:
- 1201 Intervals 差分约束系统
- struts中的logic:present标签 用于实现分页功能(转)
- libdvbpsi 源代码学习(二)
- redhat smb 配置