JSTL标签库

由SUN定义的规范,由Apache实现。Jsp Standard Tag Library,JSTL

jstl标签库的配置:

1.将jstl.jar和standard.jar拷贝到web-inf/lin下(EL表达式与JSTL没有任何关系),JSTL必须在能够支持j2ee1.4/servlet2.4/jsp2.0版本以上的容器才能运行

2.页面中引入<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%>

3.使用

核心标签

<c:out value=”${hell0}” default=”123”  escapeXml=false/>

<c:set value=”123” scope=”page”(缺省为page,在当前页面有效,还可以为request,session,application)  var=”temp” />

移除<c:remove  var=”temp”  />

判断<c:if test=”${v1 lt v2}”> v1小于v2就进来了</c:if>

     <c:if test=”${empty v3}”>v3为空就进来</c:if>

条件控制:<c:choose>

               <c:when test=”${empty v4}”>v4为空进来</c:when>

<c:otherwise>其他的则进到这里</c:otherwise></c:choose>

循环控制:<c:foreach></c:foreach>  varStatus ,begin,end,step

<c:choose>

<c:when test=”${empty userlist}”>

<tr><td>没有符合条件的数据</td></tr>

</c:when>

<c:otherwise>

<c:foreach items=”${userlist}”var=”user” varStatus=”vs”>//循环取数据

<c:choose><c:when test=”${vs.count%2==0}”>

<tr bgcolor=”red”></c:when>

<c:otherwise><tr></c:otherwise>

<td><c:out value=”${user.username}” /></td><td><c:out value=”${user.age}”/></td><td></td></tr>

</c:choose>

</c:foreach>

</c:otherwise>

普通循环<c:foreach begin=”1” end=”10”>a<br></c:foreach>

输出map <c:foreach items=”${mapvalue}”  var=”v”>${v.key}=${v.value}</c:foreach>

循环控制<c:forTokens>

<c:forTokens items=${strTokes} delims=”,”(间隔符) var=”v”/>

        catch <c:catch>不活异常

<c:catch var=”exinfo”><% inter.parseInt(“asd”)%></c:catch>会将异常信息保存在exinfo中  ${exinfo}

<c:import> 引入URL中的页面

<c:import url=”http://localhost:8080/index.jsp” />

<c:url> <c:param>

<c:url value=”http://localhost:8080/drp/sysmgr/user_add.jsp” var=-“V”>

<c:param name=”username” value=”Jack”/>

<c:param name=”age” value=”22” />

</url>

<c:redirect>重定向

<c:redirect context=”/Struts_login” Url=”/index.jsp”  /> 重定向

格式化标签

<fmt:formatNumber>格式化数字

1

<fmt:formatDate>格式化日期

 2

原文地址:https://www.cnblogs.com/guaniu/p/2324148.html