<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>s:if标签测试</title> </head> <body> <!-- 在Stack Context中定义一个age属性,其值为29 --> <s:set name="age" value="29"/> <!-- 如果Stack Context中的age属性大于60 --> <s:if test="#age>60"> 老年人 </s:if> <!-- 如果Stack Context中的age属性大于35 --> <s:elseif test="#age>35"> 中年人 </s:elseif> <!-- 如果Stack Context中的age属性大于15 --> <s:elseif test="#age>15"> 青年人 </s:elseif> <s:else> 少年 </s:else> </body> </html> </span>
<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用s:append标签拼接集合和Map</title>
</head>
<body>
<!-- 使用append将List和Map集合拼接在一起
新集合实际上是Map集合,其名字为newList -->
<s:append var="newList">
<s:param value="#{'Java':'ljh',
'C#':'lsz'}" />
<s:param value="#{'0629',
'0404'}" />
</s:append>
<table border="1" width="280">
<!-- 使用iterator迭代newList集合 -->
<s:iterator value="#newList" status="st">
<tr <s:if test="#st.odd">
style="background-color:#bbbbbb"</s:if>>
<td><s:property value="key"/></td>
<td><s:property value="value"/></td>
</tr>
</s:iterator>
</table>
</body>
</html>
</span>
<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用s:generator生成集合</title>
</head>
<body>
<table border="1" width="240">
<!-- 使用generator标签将指定字符串解析成Iterator集合
在generator标签内,得到的List集合位于ValueStack顶端 -->
<s:generator val="'Java
,C#,
C++'" separator=",">
<!-- 没有指定迭代哪个集合,直接迭代ValueStack顶端的集合 -->
<s:iterator status="st">
<tr <s:if test="#st.odd">
style="background-color:#bbbbbb"</s:if>>
<td><s:property/></td>
</tr>
</s:iterator>
</s:generator>
</table>
</body>
</html></span>
<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用s:merge标签迭代Map</title>
</head>
<body>
<s:merge id="newList">
<s:param value="#{'Java':'ljh',
'C#':'lsz'}" />
<s:param value="#{'0629',
'0404'}" />
</s:merge>
<table border="1" width="320">
<s:iterator value="#newList" status="st">
<tr <s:if test="#st.odd">style="background-color:#bbbbbb"</s:if>>
<td><s:property value="key"/></td>
<td><s:property value="value"/></td>
</tr>
</s:iterator>
</table>
</body>
</html></span>
<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用s:sort对集合元素进行排序</title>
</head>
<body>
<!-- 定义一个Comparator实例 -->
<s:bean var="mycomparator" name="org.ljh.app.util.MyComparator"/>
<!-- 使用自定义的排序规则对目标集合进行排序 -->
<s:sort source="{'Java'
,'C#'
,'C++'
,'Ajax'
,'XML'}"
comparator="#mycomparator"
var="sortedList"/>
输出page范围的sortedList属性:<br/>
${pageScope.sortedList}
<table border="1" width="300">
<!-- 迭代page范围内的sortedList属性 -->
<s:iterator status="st" value="#attr.sortedList">
<tr <s:if test="#st.odd">
style="background-color:#bbbbbb"</s:if>>
<td><s:property/></td>
</tr>
</s:iterator>
</table>
</body>
</html></span>
<span style="font-size:18px;">public class MyComparator implements Comparator
{
//决定两个元素大小的方法
public int compare(Object element1, Object element2)
{
//根据元素字符串长度来决定大小
return element1.toString().length()
- element2.toString().length();
}
}</span>
<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用s:subset标签截取集合元素</title>
</head>
<body>
<!-- 定义一个Decider Bean -->
<s:bean var="mydecider" name="org.ljh.app.util.MyDecider"/>
<!-- 使用自定义的Decider实例来截取目标集合,生成子集
指定var属性,将生成的Itertor放入pageScope中 -->
<s:subset source="{<span style="font-family: SimSun; ">'Java'</span></span><pre name="code" class="html"><span style="font-size:18px;"> ,'C#'
,'C++'
,'Ajax'
,'XML'</span></pre><span style="font-size:18px;">}" decider="#mydecider"var="newList"/>直接输出page范围的newList属性:<br/>${pageScope.newList}<table border="1" width="240"><!-- 迭代page范围内的newList属性 --><s:iterator status="st" value="#attr.newList"><tr <s:if test="#st.odd">style="background-color:#bbbbbb"</s:if>><td><s:property/></td></tr></s:iterator></table></body></html></span>
<span style="font-size:18px;">//用户自定义的Decider类,实现了SubsetIteratorFilter.Decider接口
public class MyDecider
implements SubsetIteratorFilter.Decider
{
//实现Decider接口必须实现的decide方法,
//该方法决定集合中的元素是否被选入子集
public boolean decide(Object element) throws Exception
{
String str = (String)element;
//如果集合元素(字符串)中包含Java EE子串,即可被选入子集
return str.indexOf("Java") > 0;
}
}</span>
<s:actionname="actionTag!default" executeResult="true"namespace="/generic/dataTag"> <paramname="username" value=" "/>给action属性复制 <paramname="email" value=" "/> </s:action>
<s:pushvalue="#session.user"> <s:propertyvalue="username"> <s:propertyvalue="sex"> <s:propertyvalue="emai"> </s:push>
<span style="font-size:18px;"><html>
<head>
<title>使用s:component标签</title>
</head>
<body>
<h3>使用s:component标签</h3>
使用默认主题(xhtml),默认主题目录(template)<br/>
使用mytemplate.jsp作为视图组件
<s:component template="mytemplate.jsp">
<s:param name="list" value="{'Java'
,'C#'
,C++'}"/>
</s:component>
<hr/>
使用自定义主题,自定义主题目录<br/>
使用myAnotherTemplate.jsp作为视图组件
<s:component
templateDir="myTemplateDir"
theme="myTheme"
template="myAnotherTemplate.jsp">
<s:param name="list" value="
{'Java'
,'C#'
,C++'}"/>
</s:component>
</body>
</html>
</span>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有