JSTL標籤庫

首先需要導入

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

標籤裏面可使用EL表達式,與其是一夥的...

0.對路徑進行構造,可絕對路徑也可以相對路徑

<c:url var="myURL" value="http://localhost:8080/exercise/if.jsp">
	<c:param name="username" value="lne" />
	<c:param name="password" value="lne" />
</c:url>
相對路徑:
<c:url var="yourURL" value="if.jsp?username=lne&password=lne" />

1.輸出

<c:out value="${param.name }" escapeXml="false">
	get fail
</c:out>
<%--如果value值爲獲取到的話就執行default--%>
<%--false不轉化爲html文檔,未標明默認轉化 --%>
2.設定&條件
<c:set value="lne" var="root" />
<%--設定root的值爲lne --%>
<c:if test="${param.username==root}">
	the name is lne.
</c:if>
<%--test中boolean爲true,則輸出該語句 --%>

3.選擇

<c:choose>
	<c:when test="false">
		unknow<br />
	</c:when>
	<%--只要最開始的一個爲真,其餘都不執行 --%>
	<c:when test="...">
		the answer
	</c:when>
	<%--非真則不執行--%>
	<c:otherwise>
		default
	</c:otherwise>
	<%--未完成的任務,執行該句,可沒有該句 --%>
</c:choose>

4.循環

可設置起始,步長

<c:forEach var="i" items="<%=phones %>" begin="0" end="2" step="2">
	${i }<br />
</c:forEach>
<%!
	String[] phones= {"xiaomi","oppo","vivo"};
%>
<table border="1">
<tr>
	<td>num</td>
	<td>name</td>
</tr>
<c:forEach var="i" items="<%=phones %>" varStatus="status">
	<tr>
		<td>${status.count}</td>
		<td>${i}</td>
	</tr>
</c:forEach>     
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章