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 }