struts标签

来源:互联网 发布:上海市数据服务网 编辑:程序博客网 时间:2024/05/14 02:59
 

<!-- 因为在bean标签内,Person实例位于ValueStack的栈顶,

              故可以直接访问lee.Person实例 -->

 

 <s:bean name="org.crazyit.app.dto.Person">

   <!-- 使用param标签为Person类的实例传入参数 -->

   <s:param name="name" value="'yeeku'"/>

   <s:param name="age" value="29"/>

   <!-- 因为在bean标签内,Person实例位于ValueStack的栈顶,

      故可以直接访问lee.Person实例 -->

   Person实例的name为:<s:property value="name"/><br/>

   Person实例的age为:<s:property value="age"/>

</s:bean>

 

<!-- 使用bean标签创建一个Person类的实例,为其指定了var属性 -->

<s:bean name="org.crazyit.app.dto.Person" var="p">

   <!-- 使用param标签为Person类的实例传入参数 -->

   <s:param name="name" value="'yeeku'"/>

   <s:param name="age" value="29"/>

</s:bean>

<!-- 根据JavaBean实例指定的var属性来访问JavaBean实例 -->

Person实例的name为:<s:property value="#p.name"/><br/>

Person实例的age为:<s:property value="#p.age"/><br/>

${requestScope.p}

 

调试时用

 <s:debug/>

s:itertor标签测试

<table border="1" width="300">

<!-- 迭代输出List集合 -->

<s:iterator value="{'疯狂Java讲义',

  '轻量级Java EE企业应用实战',

  '经典Java EE企业应用实战'}"

  id="name" status="st">

  <tr <s:if test="#st.odd">

    style="background-color:#bbbbbb"</s:if>>

    <td><s:property value="name"/></td>

  </tr>

</s:iterator>

</table>

<table border="1" width="350">

  <tr>

    <th>书名</th>

    <th>作者</th>

  </tr>

<!-- 对指定的Map对象进行迭代输出,并指定status属性 -->

<s:iterator value="#{'疯狂Java讲义':'aa',

  '轻量级Java EE企业应用实战':'aa' ,

  '经典Java EE企业应用实战':'aa'}"

  id="score" status="st">

  <!-- 根据当前被迭代元素的索引是否为奇数来决定是否使用背景色 -->

  <tr <s:if test="#st.odd">

    style="background-color:#bbbbbb"</s:if>>

    <!-- 输出Map对象里Entry的key -->

    <td><s:property value="key"/></td>

    <!-- 输出Map对象里Entry的value -->

    <td><s:property value="value"/></td>

  </tr>

</s:iterator>

</table>

 

 <

<%@ page contentType="text/html; chars <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

    <%@taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

   <table border="1" width="300">

 

<s:iterator value="{'aa',

  'bb',

  'cc'}"

  id="name" status="st">

  <tr <s:if test="#st.odd">

    style="background-color:#bbbbbb"</s:if>>

    <td><s:property value="name"/></td>

  </tr>

</s:iterator>

</table>

<table border="1" width="350">

  <tr>

    <th>11</th>

    <th>22</th>

  </tr>

 

<s:iterator value="#{'aa':'11',

  'bb':'11' ,

  'cc':'11'}"

  id="score" 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>

 

@<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>

<%@taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

  <title>使用s:itertor标签迭代List</title>

</head>

<body>

<table border="1" width="200">

<!-- 迭代输出List集合 -->

<s:iterator value="{'疯狂Java讲义',

  '轻量级Java EE企业应用实战',

  '经典Java EE企业应用实战'}"

  id="name" status="st">

  <tr <s:if test="#st.odd">

    style="background-color:#bbbbbb"</s:if>>

    <td><s:property value="name"/></td>

  </tr>

</s:iterator>

</table>

</body>

</html>

 

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>

<%@taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

  <title>使用s:itertor标签迭代Map</title>

</head>

<body>

<table border="1" width="240">

  <tr>

    <th>书名</th>

    <th>作者</th>

  </tr>

<!-- 对指定的Map对象进行迭代输出,并指定status属性 -->

<s:iterator value="#{'疯狂Java讲义':'李刚',

  '轻量级Java EE企业应用实战':'李刚' ,

  '经典Java EE企业应用实战':'李刚'}"

  id="score" status="st">

  <!-- 根据当前被迭代元素的索引是否为奇数来决定是否使用背景色 -->

  <tr <s:if test="#st.odd">

    style="background-color:#bbbbbb"</s:if>>

    <!-- 输出Map对象里Entry的key -->

    <td><s:property value="key"/></td>

    <!-- 输出Map对象里Entry的value -->

    <td><s:property value="value"/></td>

  </tr>

</s:iterator>

</table>

</body>

</html>