JSTL标签

来源:互联网 发布:lols8 知乎 编辑:程序博客网 时间:2024/04/29 03:49
 
  1. <%@ page language="java" contentType="text/html; charset=GB18030"
  2.     pageEncoding="GB18030"%>
  3. <%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>    
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  8. <title>测试jstl核心库</title>
  9. </head>
  10. <body>
  11.     <h1>测试jstl核心库</h1>
  12.     <hr>
  13.     <li>测试c:out</li><br>
  14.     hello(default):<c:out value="${hello}"/><br>
  15.     hello(el表达式):${hello }<br>
  16.     hello(default="123"):<c:out value="${abc}" default="123"/><br>
  17.     hello(default="123"):<c:out value="${abc}">123</c:out><br>
  18.     bj(defalut):<c:out value="${bj}"/><br>
  19.     bj(escapeXml="true"):<c:out value="${bj}" escapeXml="true"/><br>
  20.     bj(escapeXml="false"):<c:out value="${bj}" escapeXml="false"/><br>
  21.     bj(el表达式):${bj }<br>
  22.     <p>
  23.     <li>测试c:set和c:remove</li><br>
  24.     <c:set value="123" var="temp"/>
  25.     temp:${temp }<br>
  26.     <c:remove var="temp"/>
  27.     temp:${temp }<br>
  28.     <p>
  29.     <li>测试条件控制标签c:if</li><br>
  30.     <c:if test="${v1 lt v2}" var="v">
  31.         v1小于v2<br>v=${v }<br>
  32.     </c:if>
  33.     <c:if test="${empty v3}">
  34.         v3为空<br>
  35.     </c:if>
  36.     <c:if test="${empty v4}">
  37.         v4为空<br>
  38.     </c:if>
  39.     <p>
  40.     <li>测试条件控制标签c:choose,c:when,c:otherwise</li><br>
  41.     <c:choose>
  42.         <c:when test="${v1 lt v2}">
  43.             v1小于v2<br>
  44.         </c:when>
  45.         <c:otherwise>
  46.             v1大于v2<br>
  47.         </c:otherwise>
  48.     </c:choose>
  49.     <c:choose>
  50.         <c:when test="${empty v4}">
  51.             v4为空<br>
  52.         </c:when>
  53.         <c:otherwise>
  54.             v4不为空<br>
  55.         </c:otherwise>
  56.     </c:choose>
  57.     <p>
  58.     <li>测试循环控制标签c:forEach</li><br>
  59.     <table border="1">
  60.         <tr>
  61.             <td>姓名</td>
  62.             <td>年龄</td>
  63.             <td>所属组</td>
  64.         </tr>
  65.         <c:choose>
  66.             <c:when test="${empty userlist}">
  67.                 <tr>
  68.                     <td colspan="3">没有符合条件的数据!</td>
  69.                 </tr>
  70.             </c:when>
  71.             <c:otherwise>
  72.                 <c:forEach items="${userlist}" var="u">
  73.                     <tr>
  74.                         <td>${u.username }</td>
  75.                         <td>${u.age }</td>
  76.                         <td>${u.group.name }</td>
  77.                     </tr>
  78.                 </c:forEach>
  79.             </c:otherwise>
  80.         </c:choose>
  81.     </table>    
  82.     <p> 
  83.     <li>测试循环控制标签c:forEach,varstatus</li><br>
  84.     <table border="1">
  85.         <tr>
  86.             <td>姓名</td>
  87.             <td>年龄</td>
  88.             <td>所属组</td>
  89.         </tr>
  90.         <c:choose>
  91.             <c:when test="${empty userlist}">
  92.                 <tr>
  93.                     <td colspan="3">没有符合条件的数据!</td>
  94.                 </tr>
  95.             </c:when>
  96.             <c:otherwise>
  97.                 <c:forEach items="${userlist}" var="user" varStatus="vs">
  98.                     <c:choose>
  99.                         <c:when test="${vs.count % 2 == 0}">
  100.                             <tr bgcolor="red">
  101.                         </c:when>
  102.                         <c:otherwise>
  103.                             <tr>
  104.                         </c:otherwise>
  105.                     </c:choose>
  106.                                 <td>
  107.                                     <c:out value="${user.username}"/>
  108.                                 </td>
  109.                                 <td>
  110.                                     <c:out value="${user.age}"/>
  111.                                 </td>
  112.                                 <td>
  113.                                     <c:out value="${user.group.name}"/>
  114.                                 </td>
  115.                             </tr>                   
  116.                 </c:forEach>
  117.             </c:otherwise>
  118.         </c:choose>
  119.     </table>
  120.     <p>
  121.     <li>测试循环控制标签c:forEach,begin,end,step</li><br>
  122.     <table border="1">
  123.         <tr>
  124.             <td>姓名</td>
  125.             <td>年龄</td>
  126.             <td>所属组</td>
  127.         </tr>
  128.         <c:choose>
  129.             <c:when test="${empty userlist}">
  130.                 <tr>
  131.                     <td colspan="3">没有符合条件的数据!</td>
  132.                 </tr>
  133.             </c:when>
  134.             <c:otherwise>
  135.                 <c:forEach items="${userlist}" var="user" begin="2" end="8" step="2">
  136.                     <tr>
  137.                         <td>${user.username}</td>
  138.                         <td>${user.age}</td>
  139.                         <td>${user.group.name }</td>
  140.                     </tr>
  141.                 </c:forEach>
  142.             </c:otherwise>
  143.         </c:choose>
  144.     </table>    
  145.     <p>
  146.     <li>测试循环控制标签c:forEach,普通循环</li><br>
  147.     <c:forEach begin="1" end="10">
  148.         a<br>
  149.     </c:forEach>
  150.     <p>
  151.     <li>测试循环控制标签c:forEach,输出map</li><br>
  152.     <c:forEach  items="${mapvalue}" var="v">
  153.         ${v.key }=${v.value }<br>
  154.     </c:forEach>
  155.     <p>
  156.     <li>测试循环控制标签c:forTokens</li><br>
  157.     <c:forTokens items="${strTokens}" delims="," var="v">
  158.         ${v }<br>
  159.     </c:forTokens>
  160.     <p>
  161.     <li>测试c:catch</li><br>
  162.     <%
  163.         try {
  164.             Integer.parseInt("asdfsdf");
  165.         }catch(Exception e) {
  166.             out.println(e.getMessage());
  167.         }   
  168.     %>
  169.     <p>
  170.     <c:catch var="exinfo">
  171.         <%
  172.             Integer.parseInt("asdfsdf");
  173.         %>
  174.     </c:catch>
  175.     ${exinfo }<br>
  176.     <p>
  177.     <li>测试c:import</li><br>
  178.     <c:import url="http://localhost:8080/struts_login"/>
  179.     <p>
  180.     <li>测试c:url和c:param</li><br>
  181.     <c:url value="http://localhost:8080/drp/sysmgr/user_add.jsp" var="v">
  182.         <c:param name="username" value="Jack"/>
  183.         <c:param name="age" value="20"/>
  184.     </c:url>
  185.     ${v }<br>
  186.     <li>测试:redirect</li><br>
  187.     <c:redirect context="/struts_login" url="/index.jsp"/>
  188. </html>
原创粉丝点击