1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@ taglib uri="/struts-tags" prefix="s"%> 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 4 <html> 5 <head> 6 <title>Struts中的标签</title> 7 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 <!-- 12 <link rel="stylesheet" type="text/css" href="styles.css"> 13 --> 14 15 </head> 16 17 <body> 18 <s:property value="username"/><br/> 19 <s:property/><br/><!-- 默认取ValueStack中的栈顶对象 --> 20 21 <hr/> 22 <s:set var="list" value="{'a','b','c'}"></s:set> 23 <s:iterator value="#list"><!-- 遍历时,会将当前遍历的对象放到ValueStack的栈顶 l="a" --> 24 <s:property/><br/> 25 </s:iterator> 26 <hr/> 27 <s:set var="map" value="#{'a':'aa','b':'bb'}"></s:set> 28 <s:iterator value="#map"><!-- 遍历时,会将当前遍历的对象放到ValueStack的栈顶 me=Map.Entry --> 29 <s:property value="key"/>:<s:property value="value"/><br/> 30 </s:iterator> 31 <hr/> 32 <s:set var="grade" value="'B'"></s:set><!-- 如果把一个字符串当做了表达式,请使用引号引起来就是字符串了 --> 33 <s:if test="#grade=='A'"> 34 优秀 35 </s:if> 36 <s:elseif test="#grade=='B'"> 37 良好 38 </s:elseif> 39 <s:else> 40 不及格 41 </s:else> 42 <hr/> 43 44 <s:set var="records" value="{'书籍1','书籍2','书籍3','书籍4','摄影艺术指导','道德与法制'}"></s:set> 45 46 <table border="1"> 47 <tr> 48 <th>序号</th> 49 <th>书名</th> 50 </tr> 51 <s:iterator value="#records" status="vs"> 52 <tr bgcolor="<s:property value='#vs.even?"red":"green"'/>"> 53 <td> 54 <s:property value="#vs.count"/> 55 </td> 56 <td> 57 <s:property/> 58 </td> 59 </tr> 60 </s:iterator> 61 </table> 62 <s:url action="a12" var="url"><!-- 还对URL进行了重写 --> 63 <s:param name="username" value="'admin'"></s:param><!-- value的取值当做表达式了 --> 64 <s:param name="age" value="'38'"></s:param> 65 </s:url> 66 <a href="<s:property value="#url"/>">猛点</a> 67 <hr/> 68 <s:set value="'addCustomer'" var="addr"></s:set><!-- 存放的动作名称 --> 69 <s:url value="%{#addr}"></s:url><!-- url标签的value中的取值,默认是当做字符串的。 如果想把当做表达式来做,请使用%{}--> 70 <s:debug></s:debug> 71 </body> 72 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@page import="cn.itcast.action.StudentAction"%> 3 <%@page import="cn.itcast.action.Book"%> 4 <%@ taglib uri="/struts-tags" prefix="s"%> 5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 6 <html> 7 <head> 8 <title>Struts2中的标签</title> 9 10 <meta http-equiv="pragma" content="no-cache"> 11 <meta http-equiv="cache-control" content="no-cache"> 12 <meta http-equiv="expires" content="0"> 13 <!-- 14 <link rel="stylesheet" type="text/css" href="styles.css"> 15 --> 16 17 </head> 18 19 <body> 20 <s:form action="a11" namespace="/test"> 21 <s:textfield name="username"></s:textfield> 22 <s:password name="password"></s:password> 23 <hr/> 24 <s:checkboxlist name="hobby" list="{'吃饭','睡觉','学习'}" value="{'学习','吃饭'}"></s:checkboxlist><br/> 25 <s:checkboxlist list="hobby1" name="hh" value="hobby2"></s:checkboxlist><br/> 26 <s:checkboxlist list="#{'北京':'0','上海':'1','山东':'2'}" name="province" listKey="value" listValue="key" value="{'2'}"></s:checkboxlist> 27 28 <% 29 List ps = new ArrayList(); 30 ps.add(new Book("abook",10f)); 31 ps.add(new Book("bbook",11f)); 32 ps.add(new Book("cbook",12f)); 33 request.setAttribute("ps",ps); 34 %> 35 <s:checkboxlist list="#attr.ps" name="b" listKey="price" listValue="name"></s:checkboxlist> 36 <hr/> 37 38 <s:radio list="#{'0':'女','1':'男'}" listKey="key" listValue="value"></s:radio> 39 <hr/> 40 <s:select list="#{'021':'上海','010':'北京','0531':'济南'}" listKey="key" listValue="value" value="'010'"></s:select> 41 42 </s:form> 43 </body> 44 </html>