读书人

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

发布时间: 2012-10-25 10:58:58 作者: rapoo

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

14、<s:if test=用法一:<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"; }}

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

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

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

用法一:直接包含一个jsp页面,包含的jsp页面先解析,再在该页面展现<s:include value=用法二:<s:include value= <s:param name=也可以这样的写:<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>

读书人网 >软件架构设计

热点推荐