JSTL 搞java的人必備的東西

來源:互聯網
上載者:User
 <%@ 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="" />,     </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=""/></td>          <td><c:out value="0"/></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=""/></td></tr>    </c:forTokens>    </table><p> 四、使用步長    <table>      <tr><th>second</th>      <th>second</th></tr>      <c:forEach var="seconds" begin="0" end="1800" step="60">      <tr><td><c:out value=""/></td>          <td><c:out value=""/></td></tr>     </c:forEach>    </table> <p> 五、對數組進行迴圈<p>   <% int ai[] = {10, 20, 30, 40, 50};   pageContext.setAttribute("ary", ai);   %>   <c:forEach var="i" items="">     <c:out value=""/>*   </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="">      <tr><td><c:out value=""/></td>          <td><c:out 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="">   <c:out value=""/><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="" begin="2" end="10" step="2">      <c:out value=""/><br>    </c:forEach><p> 八、map<p>    <c:forEach var="prop" items="" begin="1" end="5">      <c:out value=""/> = <c:out value=""/><br>    </c:forEach>    </body> </html> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.