subset标签用于筛选集合里元素。它使用一个Filter,将不合格的元素过滤掉,剩下原集合的一个子集。例如:
1 <%@ page language="java" contentType="text/html; charset=UTF-8"%> 2 <%@ taglib uri="/struts-tags" prefix="struts"%> 3 <%@ taglib uri="/struts-tags" prefix="s"%> 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 5 <html> 6 <head> 7 <title>My JSP 'index.jsp' starting page</title> 8 <meta http-equiv="pragma" content="no-cache"> 9 <meta http-equiv="cache-control" content="no-cache"> 10 <meta http-equiv="expires" content="0"> 11 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 12 <meta http-equiv="description" content="This is my page"> 13 <!-- 14 <link rel="stylesheet" type="text/css" href="styles.css"> 15 --> 16 17 <struts:head theme="ajax" /> 18 19 <style type="text/css"> 20 body,td { 21 font-size: 12px; 22 } 23 </style> 24 </head> 25 26 <body> 27 28 29 <h3><font color="#0000FF"> <struts:append />标签 </font></h3> 30 31 <!-- 可以结合SubsetAction,通过subset.action测试效果 --> 32 <s:subset source="maleList" decider="decider"> <!-- 筛选标签 --> 33 <s:iterator> <!-- 遍历筛选后的结果 --> 34 <s:property /> <!-- 输出每个遍历的值 --> 35 <br> 36 </s:iterator> 37 </s:subset> 38 39 </body> 40 </html>
maleList是Action中的集合属性,decider是Action中的Filter属性。decider必须实现SubsetIteratorFilter接口以及decide()方法。