EL表达式
EL表达式的基本语法 : ${表达式}
一般替换out.println();
<h1> 姓名:${requestScope.student.name}</h1>
作用域对象
忽略书写作用域对象时,el则按作用域从小到大依次尝试获取
作用域对象 | 描述 |
---|---|
pageScope | 从当前页面取值 |
requestScope | 从当前请求中获取属性值 |
sessionScope | 从当前会话中获取属性值 |
applicationScope | 从当前应用获取全局属性值 |
EL表达式
语法: ${ [ 作用域 . ]属性名 . [ 子属性] }
EL输出参数值
语法: ${ param.参数名 }
eg:
<h1> 姓名:${param.teach}</h1>
JSTL标签库
安装
https://tomcat.apache.org/download-taglibs.cgi
类别 |
---|
核心标签库 --core |
格式化输出标签库 --fmt |
SQL操作标签库 --sql |
XML操作标签库 --xml |
函数标签库 --functions |
使用核心标签库(core)要再上边加上一句话,如下:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
标签 | 描述 |
---|---|
<c: if | 单分之判断 |
< c:choose> | 多选择判断 |
<c: when > | 相当与判断 |
< c:otherwise> | 相当于else |
eg:
判断
<c:if test="${score>=60 }">
<h1>及格了<</h1>
</c:if>
多选择
<c:choose>
<c:when test="${score>=60}">
<h1>及格了<</h1>
</c:when>
<c:otherwise>
<h1>其它<</h1>
</c:otherwise>
</c:choose>
集合遍历
标签 | 描述 |
---|---|
< c:forEach> | 集合遍历 |
< c:set> | 用于保存数据 |
eg:
<%--items shu数据源 varb变量 varStatus ${idex.index}是循环索引--%>
<c:forEach var="p" items="${requestScope.companies}" varStatus="idx">
<h2>${idex.index}.${c.cname}-${c.url}</h2>
</c:forEach>
倒叙:
<c:set var="startIndex" value="${fn:length(persons)-1 }"></c:set>
<c:forEach var="person" items="${persons }" varStatus="status">
<tr>
<td>${persons[startIndex - status.index].age }</td>
<td>${persons[startIndex - status.index].name }</td>
</tr>
</c:forEach>
fmt格式化标签库
标签 | 描述 |
---|---|
URI | http://java.sun.com/jsp/jstl/fmt |
<fmt:formatDate value="" pattern=""> | 格式化日期标签 |
<fmt:formatNumber value="" pattern=""> | 格式化数字标签 |
<c:out> | 默认输出,是否转译 |
//yyyy -四位年 MM-两位月 dd-两位日 HH - 24小时制 hh-12小时制 mm-分钟 ss-秒 SSS-毫秒
<fmt:formatDate value="${requestScope.now}" pattern="yyyy年MM月dd日HH时mm分ss秒"></fmt:formatDate>
// 3位一分割 保留小数点后两位
<fmt:formatNumber value="amt" pattern="0,000.00"></fmt:formatNumber>
//当value值传入一个null,则默认输出一个 "无"
<c:out value="${nothing}" default="无"></c:out>
//将这个html内容进行转译 false则不进行
<c:out value="${html}" escapeXml="ture"></c:out>