时隔几天,又开始整理一下了,本文章视频来自于 https://edu.aliyun.com/roadmap/java ,笔记为自己所写, 内容比较简单,但容易忘掉,记录下来,希望这里能对朋友们有所帮助叭。
19- EL 表达式
- jsp 内置语言;
全域查找:
- pageContext. setAttribute(“xxx”,“pageContext”);
- request. setAttribute(“xxx”,“request”);
- session. setAttribute(“xxx”,“session”);
- application. setAttribute(“xxx”,“application”);
${ xxx }// 分别显示以上的四个域内的value;
${ requestScope.xxx } // 查找指定域内的value;注意,必须 + Scope后缀;
- JavaBean 导航
11 个内置对象:
-
EL 替代:<%=…%>, 输出
- 前十个map
- pageScope
- requestScope
- sessionScope
- applicationScope
- param
- param. name( single ) & paramValues. names[0]( arrays )
- paramValues
- header
- 对应请求头,key头名称,value头值,
- headerValues
- initParam
- <context-param>
- cookie
- pageContext
${pageContext.request.contextPath }
项目路径;
EL函数库:
<% taglib prefix="fn" uri="http://java.sum.com/jsp/jstl/functions" %>
<h1>
the EL function:
</h1>
${fn:length(array)}
20- JSTL 标签库
- apache 提供,依赖于 EL
- 四大库:
- core:核心标签库:tag–》c
- out & set:out:解决是否转移比如:(’>’)
- remove
- url
- value: 在路径前面加上项目名;
- 加上param:提供参数;
- <c:url value="/index. jsp"> <c:param name=“username” value=“Jason”/> </ c:url>
- 逻辑标签:
- if
- <c:if test=“boolean”>…</c :if>
- choose
- <c:choose >
- <c:when test=“boolean1”> … </c:when >
- <c:when test=“boolean2”> … </c:when >
- <c:otherwise >… </c:otherwise >
- </c:choose >
- forEach
- if
- fmt:格式化,format,日期,数字
- sql
- xml
- core:核心标签库:tag–》c
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: Lenovo
Date: 2021/7/1
Time: 14:39
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>choose</title>
</head>
<body>
<h1>taglib</h1>
<hr>
<c:if test="${empty param.name}">
<div><% out.print("tag if,the param.name empty;"); %></div>
</c:if>
<c:choose>
<c:when test="${empty param.name}">
<div><% out.print("tag choose.when the param.name empty;"); %></div>
</c:when>
<c:otherwise>
<div><% out.print("tag choose.when the param.name not empty:"); %>
<br>
${param.name}
</div>
</c:otherwise>
</c:choose>
</body>
</html>
forEach
<%-- forEach 中,E 大写,不是 小写的e,我裂开--%>
<c:forEach items="${ applicationScope.map }" var="entry">
<tr>
<td>${ entry.key }</td>
<td>${ entry.value }</td>
</tr>
</c:forEach>
//
<c:forEach var="item" begin="1" end="10" step="2">// step 默认为1;
${item}<br/>
</c:forEach>
the arr: <br>
<% String[] arr = { "hello","world" };
request.setAttribute("arr",arr);
%>
增强for:<br>
<c:forEach items="${arr}" var="item">// step 默认为1;
${item}<br/>
</c:forEach>
the show:
循环状态变量:
varStatus:循环状态变量;==to: 属性:count:循环元素个数,index:下标,first:是否为第一个元素,last:是否为最后一个元素,current:是否为当前元素;
fmt:
<h1>fmt:</h1>
<%
Date date = new Date();
pageContext.setAttribute("date",date);
request.setAttribute("number",3.1415926);
%>
<fmt:formatDate value="${date}" pattern="yyyy-MM-dd HH:mm:ss" />
<br>
the number:
<fmt:formatNumber value="${requestScope.number}" pattern="0.000"/><!--四舍五入-->
<fmt:formatNumber value="${requestScope.number}" pattern="#.###"/><!--区别0.00不会补位-->