JSTL

xiaoxiao2021-02-28  10

JSTL
JSP Standard Tag Library: JSP标准标记库使用步骤: 导入相关jar包导入标签库: <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

JSTL标签分类:

迭代标签条件标签通用标签

迭代标签的使用:

<c:forEach items="${list}" var="bean"> <%-- 迭代标签, item中写el表达式, var表示迭代变量 --%> <tr> <td>${bean.id}</td> <td>${bean.name}</td> <td>${bean.price}</td> <td>${bean.author}</td> <td>${bean.pubDate}</td> </tr> </c:forEach> 条件判断: 只有if,没有else示例:<c:if test="${1 == 1}">true</c:if>多个条件: 当test为真,执行when;否则执行otherwise标签中的代码示例: <c:choose> <c:when test="${1 == 2}"> 1 == 2 </c:when> <c:otherwise>1 != 2</c:otherwise> </c:choose> 通用标签: 一般项目架构时,使用示例: <%-- 设置参数 --%> <c:set var="t" scope="session" value="23"></c:set> <%-- 输出参数 --%> <c:out value="${t}"></c:out> <%-- 删除 --%> <c:remove var="t"></c:remove> <c:out value="${t}"></c:out> <%-- 没有输出内容 --> - 日期格式化: - 导入标签库:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> - 格式化代码 - 示例: <fmt:formatDate value="${bean.pubDate}" pattern="yyyy-MM-dd"/>

JSTP语法
转载请注明原文地址: https://www.6miu.com/read-2450120.html

最新回复(0)