文章目录
一、EL表达式
1.什么是EL表达式及其作用
EL 表达式的全称是:Expression Language。是表达式语言。
作用:EL表达式主要是代替jsp页面中的表达式脚本在jsp页面中进行数据的输出
2.EL表达式搜索域数据的顺序
EL 表达式主要是在 jsp 页面中输出数据。 主要是输出域对象中的数据。当四个域中都有相同的key的数据的时候,EL 表达式会按照四个域的从小到大的顺序去进行搜索,找到就输出。
<body>
<%
//往四个域中都保存了相同的 key 的数据。
request.setAttribute("key", "request");
session.setAttribute("key", "session");
application.setAttribute("key", "application");
pageContext.setAttribute("key", "pageContext");
%>
${ key }
</body>
3.EL表达式输出Bean的普通属性,数组属性。List集合属性,map集合属性
输出Person:${ p }<br/>
输出Person的name属性:${p.name} <br>
输出Person的pnones数组属性值:${p.phones[2]} <br>
输出Person的cities集合中的元素值:${p.cities} <br>
输出Person的List集合中个别元素值:${p.cities[2]} <br>
输出Person的Map集合: ${p.map} <br>
输出Person的Map集合中某个key的值: ${p.map.key3} <br>
输出Person的age属性:${p.age} <br>
4.EL表达式——运算
5.EL表达式的11个隐含对象
二、JSTL标签库(*)
JSTL 标签库 全称是指 JSP Standard Tag Library JSP 标准标签库。是一个不断完善的开放源代码的 JSP 标签库。
EL 表达式主要是为了替换 jsp 中的表达式脚本,而标签库则是为了替换代码脚本。这样使得整个 jsp 页面变得更佳简洁。
1. JSTL标签库的使用步骤
-
先导入 jstl 标签库的 jar 包。
taglibs-standard-impl-1.2.1.jar
taglibs-standard-spec-1.2.1.jar
-
第二步,使用 taglib 指令引入标签库。
<%@ taglib prefix**=“c” uri="**http://java.sun.com/jsp/jstl/core" %>
2.core核心库使用
-
<c:if />
<c:if test="${ 12 == 12 }"> <h1>12 等于 12</h1> </c:if>
-
< c:choose> < c:when> < c:otherwise>
<% request.setAttribute("height", 180); %> <c:choose> <%-- 这是 html 注释 --%> <c:when test="${ requestScope.height > 190 }"> <h2>小巨人</h2> </c:when> <c:when test="${ requestScope.height > 180 }"> <h2>很高</h2> </c:when> <c:when test="${ requestScope.height > 170 }"> <h2>还可以</h2> </c:when> <c:otherwise> <c:choose> <c:when test="${requestScope.height > 160}"> <h3>大于 160</h3> </c:when> <c:when test="${requestScope.height > 150}"> <h3>大于 150</h3> </c:when> <c:when test="${requestScope.height > 140}"> <h3>大于 140</h3> </c:when> <c:otherwise> 其他小于 140 </c:otherwise> </c:choose> </c:otherwise> </c:choose>
-
<c:forEach />
<c:forEach begin="1" end="10" var="i"> 第${i}行 </c:forEach>