Struts2标签01

URL标签。

 

典型用法:

<a href="<s:url action='hello'/>">Hello World</a>

 

该链接会直接交给一个叫做hello的action处理。

 

带参数的用法:

 

 

TextField标签

<s:textfield>

 

典型用法:

 

通过资源文件读取:

<s:textfield key="personBean.firstName"  />

对应资源文件如下:

personBean.firstName=First name

struts会把资源文件当中的key作为textfield的name属性的值,把value作为textfield的text值

 

struts2中资源文件的加载

value就是资源文件的名字。

可以用形如

<s:text name="contact" />

的方式去访问资源文件中定义的键值对。

还有一个,就是包级别的资源文件必须定义为Package.properties。名字不能更改。

struts实现国际化也是基于资源文件。例如,我们现在用的是简体中文环境,那么struts会首先搜索myResource_zh_CN.properties找不到然后搜索myResource_zh.properties,然后再找myResource.properties。

在页面中引用国际化资源的方法:

用  1.<s:text name="propertiesName"/>     2.直接使用key属性 <s:textfield key="personBean.firstName"  />     3.用ognl表达式<s:textfield name="age" label="%{getText('age')}"/>

Struts 2 will look for a property key of contact in all the property files starting with the property file that matches the Action class, then in the property files that are in the package hierarchy of the Action class, and then in any property files specified in struts.xml.

上面是struts2.2.1官方文档中的一段话。意思就是说,struts首先会去和被访问action相同的包底下去找资源文件,而后在去他的上一级包里找,最后去struts.xml里找全局properties文件,再找不到就没有了。

所以全局资源文件需要在struts.xml中声明的。具体声明的方法为:

<constant name="struts.custom.i18n.resources" value="global" />

<s:textfield name="personBean.firstName" label="First name" />
<s:url action="hello" var="helloLink">
  <s:param name="userName">Bruce Phillips</s:param>
</s:url>

<p><a href="${helloLink}">Hello Bruce Phillips</a></p>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值