Struts中logic部分标签实例

来源:互联网 发布:淘宝网店开 编辑:程序博客网 时间:2024/06/03 14:28

 本文主要内容是参考:http://x.discuz.net/131976/viewspace-90916.html

<%@ page language="java" pageEncoding="utf-8"%>
 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
       prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
       prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
       prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
       prefix="tiles"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template"
       prefix="template"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested"
       prefix="nested"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
       <html:base />
 
       <title>a.jsp</title>
<!-- -->
 
</head>
 
<body>
       This a struts page.
       <br>
       <%
                            String[] testArray = { "str0", "str1", "str2", "str3", "str4",
                            "str5" };
              pageContext.setAttribute("test", testArray);
       %>
       <logic:iterate id="array" name="test">
              <bean:write name="array" />
       </logic:iterate>
 
 
       <!--logic:iterate中的id="suibiana"bean:write中的name="suibiana"对应,名字随便起。
    logic:iterate中的name="test"pageContext.setAttribute("test",testArray)
 "test"对应。
    logic:iterate:
    length="1"表示输出几个数据;
    offset="0"表示从第几个开始输出。
-->
       <h1>
              更高级的
       </h1>
 
       <logic:iterate id="suibiana" name="test" length="1" offset="0">
              <bean:write name="suibiana" />
              <br>
       </logic:iterate>
       <br>
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       <br>
       <h1>
              logic:equal
       </h1>
       <%
       pageContext.setAttribute("equal", new Integer(1000));
       %>
       <!-- logic:equal中的name="equal"pageContext.setAttribute("equal",new Integer(1000))
   "equal"对应。
     logic:equal中的value="1000"pageContext.setAttribute("equal",new Integer(1000))
   Integer(1000)做比较。
     如果两个值相等则执行
   <logic:equal value="1000" name="equal">
       test=1001
   </logic:equal>
   logic标签中间的程序,此程序为在页面显示test=1001。否则不执行这之间的程序。
-->
 
       <logic:equal value="1000" name="equal">
       test=1001
   </logic:equal>
 
       <h1>
              logic:greaterThan
       </h1>
<!-- 比较两个值不等;但此方法不稳定value="10101"时也无输出,value="10"时有输出。
      Warning:测试后结果极难理解,尽量避免此方法的应用!
-->   
       <logic:greaterThan value="10" name="equal">
     true
    </logic:greaterThan>
   
    <br>
       <h1>
              logic:match
       </h1>
    <%
      pageContext.setAttribute("match","helloWord");
 %>
<!-- 如果logic:match中的value="hello"的值能在pageContext.setAttribute("match","helloWord")
    "helloWord"里找到,则执行logic:match标签之间的
                          <logic:match value="hello" name="match">
                          hello helloWord
                          </logic:match>
    中的内容,本程序在页面输出“hello helloWord
      如果找不到,则不执行以上程序。                     
-->
 <logic:match value="hello" name="match">
     hello helloWord
 </logic:match>
 <br>
       <h1>match:match location="start"</h1>
<!--location="start"比较是否以特定字段开始 -->      
 <logic:match value="hello" name="match" location="start">
   helloWord hello开头
 </logic:match>
 <br>
       <h1>logic:match location="end"</h1>
<!--location="end"比较是否以特定字段结尾 -->      
       <logic:match value="d" name="match" location="end">
   helloWord d结尾
    </logic:match>
 
   
</body>
</html:html>
 
原创粉丝点击