JSTL(JSP Standard Tag Library)是一个开放源代码的标签组件。是java中的一个定制标记库集。
为什么要使用JSTL
- 实现了jsp页面的代码复用
- 书写jsp的页面时可读性更强
1、核心标签库
核心标签库是JSTL中最重要的部分,是开发中最常用到的部分。

1. <c:out>

<c:out value="输出的内容" escapeXml="true" default="默认值"/>
2. <c:set>

3. <c:remove>

4. <c:catch>

<c:catch var="errmsg">
<% // 在此处产生异常
int result = 10/0;
%>
</c:catch>
<h3>异常信息:${errmsg}</h3>
5. <c:if>

<c:if test="判断条件" var="存储判断结果" scope="[page|request|session|application]">
满足条件时执行的语句
</c:if>
6. <c:choose>、<c:when>、<c:otherwise>
<c:choose>
<c:when test="判断条件">
条件满足时执行的语句
</c:when>
<c:when test="判断条件">
条件满足时执行的语句
</c:when>
<c:otherwise>
所有的<c:when>不满足时,执行本标签体内的内容
</c:otherwise>
</c:choose>
- <c:when>标签:可以出现一次或多次,用于进行条件判断。
- <c:otherwise>标签:用于所有条件都不满足时操作。
7. <c:forEach>

<%
List list = new ArrayList();
list.add("a");
list.add("b");
list.add("c");
pageContext.setAttribute("ref", list);
%>
<c:forEach var="name" items="${ref}">
${name}、
</c:forEach>
<%
Map map = new HashMap();
map.put("a", "1");
map.put("b", "2");
map.put("c", "3");
pageContext.setAttribute("ref", map);
%>
<c:forEach var="name" items="${ref}">
${name.ksy}---->${name.value}、
</c:forEach>
8. <c:forTokens>

9. <c:import>

10. <c:url>

11. <c:redirect>

2、格式化标签库

3、sql标签库

1. <sql:setDataSource>

2. <sql:query>

3. <sql:update>

4、xml标签库
5、函数标签库


网友评论