struts标签的总结1
1、取属性值及属性值得条件过滤
<body>
<!-- 从action中取属性值得方法 -->
<!-- 方法1 -->
<h1>
${message }
</h1><BR>
<!-- 方法2 -->
<h3><s:property value="message" /></h3><br>
?
<!-- 从action中取出属性的值 -->
?????? <s:set name="name" value="name" />
<!-- 对属性值的条件过滤 -->??????
??????? <s:if test="#name == 'lucy'">
??????????? lucy's file here
??????? </s:if>
??????? <s:elseif test="#name == 'jack'">
??????????? jack's file here
??????? </s:elseif>
??????? <s:else>
??????????? Other's file here
??????? </s:else>
??????? <br>
???????
</body>
?
?
2、用struts标签遍历集合中的奇数和偶是
<body>
<%
???????? List<String> list=new ArrayList<String>();
???????? list.add("jack");
???????? list.add("lucy");
???????? list.add("david");
???????? list.add("apple");
???????? list.add("oracle");
???????? list.add("java");
???????? request.setAttribute("names",list);
?%>
?<!-- 下面是struts集合取集合值得方法 -->
???????? <!--
??????????? 1、此处的空property元素用于获得当前iterator的值
??????????? 2、status被设成stuts,在iterator的里面就可以通过#stuts取得IteratorStatus的对象。IteratorStatus类包含当前序号信息,如是否第一个或最后一个,是否为奇数序号。这些信息在我们做格式化的时候,显得非常有用。
??????? -->
??? <s:iterator value="#request.names" status="stuts">?
??? <!-- 取集合中的奇数 -->?????????????
??????? <s:if test="#stuts.odd == true">
??????????? <li>White <s:property /></li>
??????? </s:if>
??? <!-- 取集合中的偶数 -->
??????? <s:else>
??????????? <li style="background-color:gray"><s:property /></li>
??????? </s:else>
??? </s:iterator><br>
?
??? ------------------------------------------------<br>
???
??? <!-- 下面是jsp中取集合值的方法 -->
??? <% Iterator ite=list.iterator();
??????? while(ite.hasNext()){
?????????? Object st=ite.next();
?????????? %>
?????????? <%=st %><br>
????? <%
??????? }
???? %>
???????
</body>