配置JSTL
原文引入:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
core 标签库
1.<c:out>例:<c:out value="${execption}"/>
表达式输出,类似于JSP中<%=%>,或EL中${el-execption}
2.<c:set>例:<c:set var="uername" value="lisi" scope="session"/>
设置范围变量的值域,javabean对象属性
3.<c:remove> 例:<c:remove var="uername" scope="session" />
相对于<c:set>,移除变量范围
4.<c: catch>
例:<c:catch var="execption">
//...代码
</c:catch>
捕获异常并保存到变量中
条件标签
1.<c:if> <c:if test="${user.visitCount==1}"> 也可声明var
//...代码
</c:if>
2.<c:choose>、<c:when>、<c:otherwise>
eg:<c:choose>
<c:when test="${execption}">
//something...
<c:/when>
<c:when test="${execption}">
//something...
<c:/when>
<c:otherwise>
//something...
<c:/otherwise>
</c:choose>
迭代标签
<c:forEach items="${用于迭代的集合}" var="迭代对象">
//something...
</c:forEach>
固定次数
<c:forEach var="i" begin="100" end="110">
${i}
</c:forEach>
格式标签
<fmt:formatNumber value="12.3" pattern=".000"/>
输出12.3000
<fmt:formatDate value="<%=new java.util.Date()%> type="date"/>
输出2007-5-21
<fmt:formatDate value="<%=new java.util.Date()%" type="time"/>
输出9:25:11
<fmt:formatDate value="<%=new java.util.Date()%" type="both"/>
输出2007-5-21 9:25:11
补充:
1.替换 request.getParameter("test"):
<c:if test="${param.test!=null}">
<c:out value="${param.test}">
</c:if>
2.<c:redirect url="a.jsp">
3.<c:redirect url="/mas.jsp" >
<c:param name="name1" value="665"/>
<c:param name="name2" value="joho"/>
</c:redirect>
4.<c:forTokens items="zhangsan:lils:as" delims=":" var="name">
${name}
</c:forTokens>
JSTL学习笔记
最新推荐文章于 2021-09-02 17:38:50 发布