strus2常用标签自己一点小小的应用3

 

14<s:if test="'"></s:if><s:else></s:else>javaif(){}else{}差不多。

用法一:<s:if test="%{false}"><div>Will Not Be Executed</div></s:if>

<s:elseif test="%{true}"><div>Will Be Executed</div></s:elseif>

<s:else> <div>Will Not Be Executed</div></s:else>

<s:if test="'foo' in {'foo','bar'}"> muhahaha</s:if><s:else>  boo</s:else>

<s:if test="'foo' not in {'foo','bar'}">  muhahaha</s:if><s:else>   boo</s:else>

用法二: <s:set name="one" value="'111'" />

 <s:property value="#attr.one"/><s:if test="#attr.one=='111'">hehwsa</s:if>

---这里用attr.会无论你存储在哪个作用域,都会找到

15<s:action name=""  executeResult="" namespace=" "></s:action>

jsp页面在加载一个action   executeResult”true””false”两个值。

当为true的时候,得到的结果为把页面加载的action得到的值展现在当前页面

当为false的时候,得到的结果是不把那action得到的结果展现出来,但是如果该在action执行时候,有参数存储在像request………….里面的时候,这时候就可以出来

比如说:public class ActionTagAction extends ActionSupport {

 public String execute() throws Exception { return "done"; }

 public String doDefault() throws Exception {

   ServletActionContext.getRequest().setAttribute("stringByAction", "This is a String put in by the action's doDefault()"); return "done"; }}

   <action name="actionTagAction" class="tmjee.testing.ActionTagAction" method="default">
    <result name="done">success.jsp</result> </action> 

jsp页面:<s:action name="/actionTagAction/default.do" executeResult="false" />

         <s:property value="#attr.stringByAction" />

16<s:include value="." />页面包含jsp页面也可以传值给包含页面

用法一:直接包含一个jsp页面,包含的jsp页面先解析,再在该页面展现<s:include value="myJsp.jsp" />

用法二:<s:include value="myJsp.jsp">

 <s:param name="param1" value="value2" /> <s:param name="param2" value="value2" />

</s:include>

也可以这样的写:<s:include value="myJsp.jsp">

 <s:param name="param1">value1</s:param><s:param name="param2">value2<s:param></s:include>

 17<s:text name=""></s:text> <s:i18n name="" ></s:i18n>

***.properties,里面取值。可以联合<s:i18n>用。

当单独用的时候,从.properties文件中取值的时候,但是这个properties文件有条件,它要在该action类中的相同的包体package下,该properties名字和该action的名字。

比如说,Properties文件:textTag.properties

webname1 = http://www.163.com.asasa   webname2 = http://www.sohu.com

   action  <action name="textTag" class="com.sterning.textTag">

                <result>/pages/dataTags/textTag.jsp</result>   </action>

   textTag.jsp页面的取值:<s:text name="webname1" id="admin"></s:text><br>

   <s:text name="webname2"></s:text><br>

   <s:text name="empname">Emp1,Emp2....</s:text><br>

   <s:text name="empname"></s:text>

最后显示的结果为:http://www.163.com.asasa     http://www.sohu.com   Emp1,Emp2....    empname 

<s:i18n>联合使用.struts2 做国际化可以用struts标签做如 <s:i18n name="temp"> 其中 name="temp" temp 是文件名字,也就是 temp_en_US.properties 里的temp名字 

<s:i18n name="temp"> <s:text name="hello"> <s:param>席一</s:param> </s:text></s:i18n>

<s:text name="hello"> hello是定义的key()   temp_en_US.properties里的内容
  hello = world {0} 
后面那个{0} 是要传进来的参数,谁给传呢,就是<
s:param>席一</s:param>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值