JSTL标签库简介

核心标签库

http://java.sun.com/jsp/jstl/core

<c:catch>,<c:url>的使用

<!-- 捕获异常 -->
     <c:catch var="exception">
         <%
             int a=1,b=0;
             out.print(a/b);
          %>
     </c:catch>
     <c:out value="${exception }"/>
     
     <!-- 建立URL -->
     <a href="<c:url value="//index.jsp"/>">哈哈哈</a>
     <a href="/index.jsp">哈哈哈</a>
     
     <!-- 使用其他Web应用URL -->
     <c:url value="/index.jsp" var="add" context="/MyMessage"/>
     <a href="${add }">呵呵</a>

<c:if>,<c:when>,<c:otherwise>,<c:choose>的使用

<%
         Calendar now=Calendar.getInstance();
         Integer hour=new Integer(now.get(Calendar.HOUR_OF_DAY));//获取小时
         request.setAttribute("time", hour);
      %>
      <c:if test="${time>=0&&time<=11 }">
          <c:set value="早上好!" var="sayhello"/>
      </c:if>
      <c:if test="${time>=12&&time<=17 }">
          <c:set value="下午好!" var="sayhello"/>
      </c:if>
      <c:if test="${time>=18&&time<=23 }">
          <c:set value="晚上好!" var="sayhello"/>
      </c:if>
      <c:out value="${sayhello }"/>
      
      <c:choose>
          <c:when test="${time>=0&&time<=11 }">
              <c:set value="moring" var="sayhello"/>
          </c:when>
          <c:when test="${time>=12&&time<=17 }">
              <c:set value="noon" var="sayhello"/>
          </c:when>
          <c:otherwise>
              <c:set value="night" var="sayhello"/>
          </c:otherwise>
      </c:choose>
      <c:out value="${sayhello }"/>
原文地址:https://www.cnblogs.com/tianhengblogs/p/5366725.html