JSTL——JSP Standard Tag Library JSP标志标签库

来源:互联网 发布:李嘉诚撤资 知乎 编辑:程序博客网 时间:2024/05/29 14:03
5个标签库:


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>


<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>


<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/function" %>




JSTL的core标签:

<c:forEach var="" items=""></c:forEach>

<c:if test=""></c:if>

<c:choose>
<c:when></c:when>(可以有多个)
<c:otherwise></c:otherwise>(只能有一个)
</c:choose>
例:
  <% 
  int i = (int)(Math.random()*4);
  pageContext.setAttribute("i",i);
   %>
  
 <c:choose>
  <c:when test="${i==1}">
  产生随机数1
  </c:when>
  <c:when test="${i==2}">
  产生随机数2
  </c:when>
  <c:when test="${i==3}">
  产生随机数3
  </c:when>
  <c:otherwise>
  error.
  </c:otherwise>
 </c:choose>




产生-100到100的随机数:
<% 
  Random r = new Random(System.currentTimeMillis());
  int i = (int)(Math.random()*101);
  if(r.nextBoolean()){
  pageContext.setAttribute("i",i);
  }
  else{
  pageContext.setAttribute("i",-i);
  }
 
   %>
   

   产生的随机数是:${i }



原创粉丝点击