JSTL核心标签库

时间:2022-10-30 18:14:58

1、set:给web域设置值的

<c:set var="lang" value="Java" scope="page"></c:set>      相当于     <% pageContext.setAttribute("lang", "Java");%>

    其中的属性一一对应

    var:属性名称

    value:属性值

    score:属性范围

<c:set var="lang" value="Java" scope="page"></c:set>
<c:set var="lang" value="Java request" scope="request"></c:set>
<c:set var="lang" value="Java session" scope="session"></c:set>
<c:set var="lang" value="Java application" scope="application"></c:set>
\${pageScope.lang} -- ${pageScope.lang}<br/>
\${requestScope.lang} -- ${requestScope.lang}<br/>
\${sessionScope.lang} -- ${sessionScope.lang}<br/>
\${applicationScope.lang} -- ${applicationScope.lang}<br/>

JSTL核心标签库

2、remove:删除指定名称的web域的值  var:名称    ; Scope:作用域

<c:remove var="lang" scope="page"/>
\${pageScope.lang} -- ${pageScope.lang}<br/>
\${requestScope.lang} -- ${requestScope.lang}<br/>
\${sessionScope.lang} -- ${sessionScope.lang}<br/>
\${applicationScope.lang} -- ${applicationScope.lang}<br/>

JSTL核心标签库

  PS:如果不写scope属性,默认删除所有作用于中的值

3、out:将内容输出

  value:指定内容(可以使用EL表达式)
      escapeXml:是否转移html规定的字符( 默认值true,转移)
      default:当前输出内容为空时,显示默认值

 <c:set var="book" value="<a href='#'>Thinking Java</a>"></c:set>

 \${book} -- ${book }
<br/>
<c:out value="${book }"></c:out> <br/>
<c:out value="${book }" escapeXml="false"></c:out><br/>
<c:out value="${book2 }" default="没有值"></c:out><br/>

  JSTL核心标签库

4、if标签:逻辑判断
        test属性:逻辑值true|false  (支持EL表达式)

<c:set var="user" value="sun"></c:set>
<c:if test="${empty user }">
user 为 null
</c:if><br/> <c:if test="${empty user1 }">
user 为 null
</c:if>

JSTL核心标签库

5、 choose标签:确定一组可以进行选择的显示结果
        1、必须放置when标签
        2、 子标签
             when标签:逻辑判断
                 test属性:填写逻辑值(可用EL表达式)
            otherwise标签:处理没有处理项,默认项(当前面都不执行时)

  <c:set var="user" value="sun"></c:set>

<c:choose>
<c:when test="${empty user }">
when:user is null <br/>
</c:when>
<c:when test="${empty user1 }">
when:user1 is null <br/>
</c:when> <c:otherwise>
othersise: Error <br/>
</c:otherwise> </c:choose>

JSTL核心标签库

6、forEach标签:进行迭代,每一条信息将显示在标签体
         items属性:确定遍历的对象(  支持EL表达式)  或 * begin属性* end属性:
        *共有
             var:确定遍历变量
            step属性:步长

<c:forEach items="${headerValues }" var="hvs">
${hvs.key}: <c:forEach items="${hvs.value }" var="h">
${h}******* <br/>
</c:forEach>
</c:forEach>

JSTL核心标签库

  <c:forEach var="i" begin="1" end="9" step="1"  >
<c:forEach var="j" begin="1" end="${i }" step="1">
${j }*${i }=${i*j } </c:forEach>
<br/>
</c:forEach>

JSTL核心标签库