JSTL学习笔记

来源:互联网 发布:键鼠套装 知乎 编辑:程序博客网 时间:2024/06/03 17:27
配置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>

1 0