EL_获取域中存储的值
- 获取值
- el表达式只能从与域对象中获取值
- 语法:-${与名称.键名}:从指定域中获取指定键的值
- 域名称:
- pageScope -----> pageContext
- requestScope -----> request
- sessionScope -----> session
- applicationScope -----> application (ServletContext)
- 举例:在request域中存储了name=张三
- 获取:$
- ${键名}:标识依次从最小的域中查找是否有该键对应的值,直到找到为止
<%--
Created by IntelliJ IDEA.
User: lihaiyang
Date: 2022/8/16
Time: 14:02
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
//在域中存储数据
request.setAttribute("name1","张三");
session.setAttribute("name2","李四");
pageContext.setAttribute("name3","王五");
application.setAttribute("name4","赵六");
%>
requestScope-->${requestScope.get("name1")}<br>
sessionScope-->${sessionScope.get("name2")}<br>
pageContext-->${pageContext.getAttribute("name3")}<br>
pageScope-->${pageScope.get("name3")}<br>
applicationScope-->${applicationScope.get("name4")}<br>
requestScope-->${requestScope.name1}<br>
sessionScope-->${sessionScope.name2}<br>
pageScope-->${pageScope.name3}<br>
applicationScope-->${applicationScope.name4}<br>
</body>
</html>
EL_获取域中存储的值_对象值
<%@ page import="com.ailyt.domain.User" %>
<%@ page import="java.util.Date" %><%--
Created by IntelliJ IDEA.
User: lihaiyang
Date: 2022/8/16
Time: 14:02
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
User user = new User();
user.setName("张三");
user.setAge(21);
user.setBirthday(new Date());
request.setAttribute("u",user);
%>
<br><br><br>
${u.name}<br><br><br>
${u.age}<br><br><br>
${u.birthday}<br><br><br>
${u.toString()}<br><br><br>
<hr>
${requestScope.get("u")}<br><br><br>
${requestScope.u}<br><br><br>
${requestScope.u.name}<br><br><br>
${requestScope.u.age}<br><br><br>
${requestScope.u.birthday}<br><br><br>
<hr>
${requestScope.get("u").name}<br><br><br>
${requestScope.get("u").age}<br><br><br>
${requestScope.get("u").birthday}<br><br><br>
</body>
</html>