<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 68, comments - 19, trackbacks - 0, articles - 1

    jstl循環

    Posted on 2010-10-21 22:23 viery 閱讀(6677) 評論(2)  編輯  收藏 所屬分類: JavaEE
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page import="java.util.*" %>

    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <html>
      <head>
        <title>JSTL測試1--c:forEach循環</title>
      </head>

      <body>
    一、整數
        <c:forEach var="i" begin="1" end="10" step="1">
          <c:out value="${i}" />,
        </c:forEach><p>
    二、計算x的平方
       <table> 
       <tr><th>Value</th> 
        <th>Square</th></tr> 
        <c:forEach var="x" begin="0" end="10" step="2"> 
        <tr><td><c:out value="${x}"/></td> 
            <td><c:out value="${x * x}"/></td></tr> 
       </c:forEach> 
      </table> <p>
    三、字符串"47,52,53,55,46,22,16,2" 分隔.
       <table border="1">
       <c:forTokens items="47,52,53,55,46,22,16,2" delims="," var="dailyPrice">
        <tr><td><c:out value="${dailyPrice}"/></td></tr>
       </c:forTokens>
       </table><p>
    四、使用步長
       <table> 
        <tr><th>second</th> 
        <th>second</th></tr> 
        <c:forEach var="seconds" begin="0" end="${pageContext.session
    .maxInactiveInterval}" step="60"> 
        <tr><td><c:out value="${seconds}"/></td> 
            <td><c:out value="${seconds}"/></td></tr> 
       </c:forEach> 
      </table> <p>
    五、對數組進行循環<p>
      <% int ai[] = {10, 20, 30, 40, 50};
      pageContext.setAttribute("ary", ai);
      %>
      <c:forEach var="i" items="${ary}">
        <c:out value="${i}"/>*
      </c:forEach><p>

     <%
       Cookie c=new Cookie("cookie1","one");
       response.addCookie(c);
     %>

     <% 
      Cookie cookies[]=request.getCookies(); 
      Cookie sCookie=null;  
      String sname=null; 
      String name=null; 
      if(cookies==null) // 如果沒有任何cookie 
        out.print("none any cookie"); 
      else 
      { 
        //out.print(cookies.length + "<br>"); 
        for(int i=0;i<cookies.length; i++) // 循環列出所有可用的Cookie 
        { 
         sCookie=cookies[i]; 
          sname=sCookie.getName(); 
          name = sCookie.getValue(); 
          out.println(sname + "->" + name + "<br>"); 
        } 
      }  
    %> 
     
    <table border="1" align="center"> 
       <tr><th>Cookie Name</th> 
        <th>Cookie Value</th></tr> 
        <c:forEach var="cook" items="${pageContext.request.cookies}"> 
        <tr><td><c:out value="${cook.name}"/></td> 
            <td><c:out value="${cook.value}"/></td></tr> 
       </c:forEach> 
      </table> <p>

    六、字符串數組循環
     <% String as[] = {
                "A first string", "La deuxieme string", "Ella troisiemo stringo"
            };
            request.setAttribute("stringArray", as);
     %><p>
     <c:forEach var="string" items="${stringArray}">
      <c:out value="${string}"/><br>
     </c:forEach>
    七、枚舉
     <%
     Hashtable hashtable1 = new Hashtable();
               pageContext.setAttribute("numberMap", hashtable1);
         
            hashtable1.put(new Integer(1), "uno");
            hashtable1.put(new Integer(2), "dos");
            hashtable1.put(new Integer(3), "tres");
            hashtable1.put(new Integer(4), "cuatro");
            hashtable1.put(new Integer(5), "cinco");
            hashtable1.put(new Integer(6), "seis");
            hashtable1.put(new Integer(7), "siete");
            hashtable1.put(new Integer(8), "ocho");
            hashtable1.put(new Integer(9), "nueve");
            hashtable1.put(new Integer(10), "diez");

            java.util.Enumeration enumeration = hashtable1.keys();
            pageContext.setAttribute("enumeration", enumeration);
    %>

       <c:forEach var="item" items="${enumeration}" begin="2" end="10" step="2">
         <c:out value="${item}"/><br>
       </c:forEach><p>
    八、map<p>
       <c:forEach var="prop" items="${numberMap}" begin="1" end="5">
         <c:out value="${prop.key}"/> = <c:out value="${prop.value}"/><br>
       </c:forEach>

     

     </body>
    </html>

    Feedback

    # re: jstl循環  回復  更多評論   

    2015-11-02 15:43 by aaaaaaaaaaaaaa
    <script>alert('aa')<script>

    # re: jstl循環  回復  更多評論   

    2015-11-02 15:45 by aaaaaaaaaaaaaa
    /><script>alert('aa')<script>
    主站蜘蛛池模板: 久久久亚洲精华液精华液精华液 | 亚洲精品国产精品乱码不卞 | 黄+色+性+人免费| 免费一级毛片在线播放放视频 | 免费黄网站在线观看| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 西西人体免费视频| 老司机亚洲精品影院| 免费A级毛片无码久久版| 黄色免费网站网址| 外国成人网在线观看免费视频| 亚洲精品亚洲人成在线观看麻豆| 巨波霸乳在线永久免费视频| 黄色免费网址大全| 亚洲欧美日本韩国| 亚洲免费福利在线视频| 亚洲高清视频在线播放| 久久亚洲国产视频| 亚洲精品国产精品乱码视色| 亚洲国产午夜中文字幕精品黄网站 | 暖暖日本免费中文字幕| 一级毛片免费观看不收费| 含羞草国产亚洲精品岁国产精品| 国产亚洲3p无码一区二区| 黄网址在线永久免费观看| 搡女人免费视频大全| 国产在线观看片a免费观看| 亚欧免费视频一区二区三区| **aaaaa毛片免费| 91老湿机福利免费体验| 无码日韩精品一区二区免费暖暖 | 999国内精品永久免费视频| 999任你躁在线精品免费不卡| 国产午夜亚洲精品| 亚洲性无码AV中文字幕| 在线亚洲午夜片AV大片| 色偷偷女男人的天堂亚洲网| 亚洲mv国产精品mv日本mv| 色偷偷女男人的天堂亚洲网 | 猫咪免费人成网站在线观看| 8x8x华人永久免费视频|