struts2标签使用

马士兵视频教程struts2标签总结。

 

property: <s:property value="username"/>
property 取值为字符串: <s:property value="'username'"/>
property 设定默认值: <s:property value="admin" default="管理员"/>
property 设定HTML: <s:property value="'<hr/>'" escape="false"/>

set 设定adminName值(默认为request 和 ActionContext): <s:set var="adminName" value="username" />

set 从request取值: <s:property value="#request.adminName" />
set 从ActionContext取值: <s:property value="#adminName" />

<%--set 设定范围: <s:set name="adminPassword" value="password" scope="page"/>
set 从相应范围取值: <%=pageContext.getAttribute("adminPassword") %>
--%>
set 设定var,范围为ActionContext: <s:set var="adminPassword" value="password" scope="session"/>
set 使用#取值: <s:property value="#adminPassword"/>
set 从相应范围取值: <s:property value="#session.adminPassword"/>

 

<%--push:<s:set name="myDog" value="new com.bjsxt.struts2.ognl.Dog('oudy')"></s:set>

push:<s:push value="#myDog">
 <s:property value="name"/>
</s:push>

push: <s:property value="name"/>
--%>


bean 定义bean,并使用param来设定新的属性值:
 <s:bean name="com.bjsxt.struts2.tags.Dog" >
  <s:param name="name" value="'pp'"></s:param>
  <s:property value="name"/>
  
 </s:bean>
 
 


bean 查看debug情况:
 <s:bean name="com.bjsxt.struts2.tags.Dog" var="myDog">
  <s:param name="name" value="'oudy'"></s:param>
 </s:bean>
 拿出值:
 <s:property value="#myDog.name"/>
 

 

include _include1.html 包含静态英文文件
<s:include value="/_include1.html"></s:include>


include _include2.html 包含静态中文文件
<s:include value="/_include2.html"></s:include>


include _include1.html 包含静态英文文件,说明%用法
<s:set var="incPage" value="%{'/_include1.html'}" />
<s:include value="%{#incPage}"></s:include>

 

 

if elseif else:
age = <s:property value="#parameters.age[0]" /> <br />
<s:set var="age" value="#parameters.age[0]" />
<s:if test="#age < 0">wrong age!</s:if>
<s:elseif test="#parameters.age[0] < 20">too young!</s:elseif>
<s:else>yeah!</s:else><br />

<s:if test="#parameters.aaa == null">null</s:if>

 


遍历集合:<br />
<s:iterator value="{1, 2, 3}" >
 <s:property/> |
</s:iterator>

自定义变量:<br />
<s:iterator value="{'aaa', 'bbb', 'ccc'}" var="x">
 <s:property value="#x.toUpperCase()"/> |
</s:iterator>

使用status:<br />
<s:iterator value="{'aaa', 'bbb', 'ccc'}" status="status">
 <s:property/> |
 遍历过的元素总数:<s:property value="#status.count"/> |
 遍历过的元素索引:<s:property value="#status.index"/> |
 当前是偶数?:<s:property value="#status.even"/> |
 当前是奇数?:<s:property value="#status.odd"/> |
 是第一个元素吗?:<s:property value="#status.first"/> |
 是最后一个元素吗?:<s:property value="#status.last"/>
 <br />
</s:iterator>

 


<s:iterator value="#{1:'a', 2:'b', 3:'c'}" >
 <s:property value="key"/> | <s:property value="value"/> <br />
</s:iterator>

 

<s:iterator value="#{1:'a', 2:'b', 3:'c'}" var="x">
 <s:property value="#x.key"/> | <s:property value="#x.value"/> <br />
</s:iterator>

 


<s:fielderror fieldName="fielderror.test" theme="simple"></s:fielderror>

 

你可能感兴趣的:(struts2,标签)