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>     
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章