您的位置:首页 > Web前端 > JavaScript

JSTL学习笔记

2016-04-27 09:26 246 查看
配置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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: