yxhxj2006

          常用鏈接

          統計

          最新評論

          JSTL(c標簽)與Struts2(s標簽)標簽的常用功能對比

          1. 條件標簽 JSTL

          <c:if test="${user.password == 'hello'}">     
          <c:choose>         
          <c:when test="${user.age <= 18}">             
          <font color="blue"/>         
          </c:when>         
          <c:when test="${user.age <= 30 && user.age > 18}">             
          <font color="red"/>         
          </c:when>         
          <c:otherwise>             
          <font color="green"/>         
          </c:otherwise>     
          </c:choose>
          </c:if>

           

          STRUTS2:

          <s:if test="#user.age <= 18">     
          <font color="blue"/>
          </s:if>
          <s:elseif test="#user.age <= 30 && user.age > 18">     
          <font color="red"/>
          </s:elseif>     
          <font color="green"/>
          </s:else>
          復制代碼
          復制代碼

          2. 迭代標簽
          JSTL:   

          <c:forEach var="user" items="${users}">     
          <c:out value="${user.userName}"/>
          </c:forEach><!-- 迭代固定次數 -->
          <c:forEach var="i" begin="1" end="10" step="3">    
          <c:out value="${i}"/>
          </c:forEach><!-- 這種循環相當于for(int i=1; i<10; i++), 其中step是指迭代的步長,默認為1. -->

          struts2:

          <s:iterator value="#users" status="stuts">     
          <s:if test="#stuts.odd == true">   <!-- 判斷是否為奇數行 -->         
          <s:property value="userName"/>     
          </s:if>     
          <s:else>         
          <s:property value="passWord"/>
          </s:else>
          </s:iterator>

          3. URL相關標簽    JSTL:

          <!-- 絕對路徑 -->
          <c:import url="http://127.0.0.1:8080/hello/hello.jsp"/><!-- 相對路徑 -->
          <c:import url="hello.jsp"/><!-- Encode -->
          <a href="<c:url value='hello.jsp'><c:param name='userName' value='cyanbomb' /></c:url>"></a><!-- 傳遞參數到指定的URL -->
          <c:import url="hello.jsp" charEncoding="gb2312">      <c:param name="userName" value="cyanbomb"/></c:import><!-- URL重定向 -->
          <c:redirect url="${myurl}"/><!-- 構造URL -->
          <c:url value="myurl" var="hello.jsp" scope="session"><c:param name="userName" value="cyanbomb"/></c:url>

          Struts2:

          <a href='<s:url value="/hello.jsp" />'>Hello</a><br />
          <s:url id="url" value="/hello.jsp"><s:param name="name">cyanbomb</s:param></s:url>
          <s:a href="%{url}">Hello</s:a>

          解除的疑問,list遍歷問題

          像這樣一個list,里面有3條記錄,每條記錄包含兩個對象,我把結果集(lstRooms)request到了頁面,想遍歷顯示RrmRooms里的id,和RrmRoomType里的name. 我用JSTL實現如下:

          <table>     
          <c:forEach var="rm" items="${lstRooms}">         
          <tr>             
          <td>${rm[0].id}</td>             
          <td>${rm[1].name}</td>         
          <tr>     
          </c:forEach></table>

          STRUTS2實現如下:

          <table>     
          <s:iterator value="#lstRooms" status="stat">         
          <tr>             
          <td>
          <s:property value="#lstRooms[#stat.index][0].id"/>
          </td>             
          <td>
          <s:property value="#lstRooms[#stat.index][1].name"/>
          </td>         
          <tr>     
          </s:iterator>
          </table>

          posted on 2014-01-15 00:38 奮斗成就男人 閱讀(412) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 当涂县| 湖北省| 龙州县| 三穗县| 杭锦后旗| 彭阳县| 丹阳市| 堆龙德庆县| 阜新| 收藏| 南川市| 区。| 天镇县| 崇义县| 永清县| 嘉荫县| 交城县| 正定县| 永吉县| 嫩江县| 卢龙县| 宜州市| 广丰县| 浦江县| 台山市| 汕尾市| 南京市| 于田县| 淮安市| 绥阳县| 建湖县| 丘北县| 鹤壁市| 蓬莱市| 香格里拉县| 黄梅县| 宣威市| 邹城市| 从江县| 海晏县| 乌审旗|