Struts数据标签

Struts数据标签

<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s" %>
<!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=UTF-8">
<title>通用标签</title>
</head>
<body>
    <h3 style="color: red;">数据标签</h3>
 
          <h3>set</h3>
          <!-- value里面放的是表达式     集合是ognl上下文 -->
          <!-- 在ognl上下文的根对象中取result属性值,赋给test1 -->
          <s:set var="test1" value="result"></s:set>
          ${test1 },${requestScope.test1 }
          
          
          <h3>property</h3>
          <!-- 取栈顶 (cal1)-->
          <s:property/>,
          <!-- 取根对象的最上面(栈顶)的属性 -->
          <s:property value="num1"/>,
          <!-- 取根对象的cal2对象的num1属性 -->
          <s:property value="cal2.num1"/>
          <!-- 取非根对象的cal2对象的num1属性值 -->
          <s:property value="#request.cal2.num1"/>
          
          
          <h3>push</h3>
          <!-- push就是将你需要的值放到栈顶,便于页面获取值 -->
          <s:push value="result">
          <s:property/>
          </s:push>
          <!-- 结束标签   结果又回到了cal1 -->
          <s:property/>                
          
          
          <h3>action</h3>
          <!-- action标签通常用来请求后台  获取初始化数据 -->
          <s:action name="tagAction" namespace="/sy" var="test2"></s:action>
          <s:property value="#test2.cal2"/>
          
          
          <h3>url</h3>
          <!-- url标签是为了生成地址所用,便于与a标签区分 -->
          <s:url namespace="/sy" action="tagAction" var="test3"></s:url>
          <s:property value="#test3"/>
          <a href="<s:property value="#test3"/>">xxx</a>
          <!-- %{test3}:str会被强制转换成OGNL表达式计算 -->
          <s:a href="%{#test3}">aaa</s:a>
          
          
          <h3>param</h3>
          <!-- 两种赋值方式: ognl表达式,字符串 -->
          <s:url namespace="/sy" action="tagAction" var="test4">
              <s:param name="test5">aaa</s:param>
              <s:param name="test6" value="num1"></s:param>
          </s:url>
          <s:property value="#test4"/>
           
          
          <h3>date</h3>
          <%
              request.setAttribute("currentDate", new Date());
            request.setAttribute("score", new Integer(70));
            request.setAttribute("names", new String[]{"gay","lisi","wangwu"});
          %>
          <%-- <s:date name="#request.currentDate"/> --%>
          <s:date name="#request.currentDate" format="yyyy-mm-dd"/>
          
          
          <h3>debug</h3>
          <s:debug/>
          
          
        <h3 style="color: red;">控制标签</h3>
            <h3>iterator/if/elseif/else</h3>
            <!-- 无序打印 -->
            <ul>
                <s:iterator var="v" value="#request.names">
                  <li>
                      <s:property value="#v"/>
                  </li>
              </s:iterator>
            </ul>
            
            
            <s:if test="#request.score>80">A</s:if>
            <s:elseif test="#request.score>60">B</s:elseif>
            <s:else>C</s:else>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/cms18374672699/article/details/83053982