JSP的 JSTL标签库

EL表达式主要是为了替换jsp中的表达式脚本,而标签库则是为了替换代码脚本,这样使得整个jsp页面变得更加整洁。

 

 

 

set标签往域中保存数据

<c:set scope="page" var="key" value="value"></c:set>

域对象:setAttribute(key,value)

scope属性设置保存到哪个域

page表示PageContext域

request表示Request域

session 表示Session域

application 表示ServletContext域

var属性设置key

value属性设置value

 

if语句代码脚本结合EL表达式

<c:if test="${12 != 12}">
    <h1>12等于12</h1>
</c:if>

 <c:forEach>标签

			<c:forEach items="${requestScope.books}" var="book">
			<tr>
				<td>${book.name}</td>
				<td>${book.price}</td>
				<td>${book.author}</td>
				<td>${book.sales}</td>
				<td>${book.stock}</td>
				<td><a href="book_edit.jsp">修改</a></td>
				<td><a href="#">删除</a></td>
			</tr>	
			
			</c:forEach>	

  

<c:choose>  <c:when> <:c:otherwise> 标签

作用:多路判断,跟switch...case...default非常像
choose标签表示开始选择判断
when标签表示每一种判断情况
otherwise标签表示else

<% request.setAttribute("height",180); %>

<c:choose>
    <c:when test="${requestScope.height} > 190">
        <h1>小巨人</h1>
    </c:when>
    <c:when test="${requestScope.height} > 180" >
        <h1>很高</h1>
    </c:when>
    <c:when test="${requestScope.height} > 170" >
        <h1>还可以</h1>
    </c:when>
    <:c:otherwise>
        <h2>残废</h2>
    </:c:otherwise>
</c:choose>

 

posted @ 2021-10-26 09:01  donkey8  阅读(22)  评论(0)    收藏  举报