黑马程序员
EL–概述
忽略EL表达式
EL–运算符
EL–获取域中存储的值
EL–获取域中存储的值–对象值
package cn
.itcast
.domain
;
import java
.text
.SimpleDateFormat
;
import java
.util
.Date
;
public class User {
private String name
;
private int age
;
private Date birthday
;
public User() {
}
public String
getBirStr(){
if (this.birthday
!=null
)
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.birthday
);
return "";
}
public User(String name
, int age
, Date birthday
) {
this.name
= name
;
this.age
= age
;
this.birthday
= birthday
;
}
public String
getName() {
return name
;
}
public void setName(String name
) {
this.name
= name
;
}
public int getAge() {
return age
;
}
public void setAge(int age
) {
this.age
= age
;
}
public Date
getBirthday() {
return birthday
;
}
public void setBirthday(Date birthday
) {
this.birthday
= birthday
;
}
@Override
public String
toString() {
return "User{" +
"name='" + name
+ '\'' +
", age=" + age
+
", birthday=" + birthday
+
'}';
}
}
<%@ page
import="cn.itcast.domain.User" %>
<%@ page
import="java.util.Date" %>
<%@ page
import="java.text.SimpleDateFormat" %><%--
Created by IntelliJ IDEA
.
User
: 联想
Date
: 2020/10/4
Time
: 17:22
To change
this template use File
| Settings
| File Templates
.
--%>
<%@ page contentType
="text/html;charset=UTF-8" language
="java" %>
<html>
<head>
<title>通过EL表达式获取数据
</title
>
</head
>
<body>
<%
User user
= new User("张三", 20, new Date());
request
.setAttribute("user",user
);
%>
name
:$
{requestScope
.user
.name
}<br>
age
:$
{user
.age
}<br>
birthday
:$
{user
.birthday
.year
}-$
{user
.birthday
.year
}-$
{user
.birthday
.month
}-$
{user
.birthday
.day
}<br>
birthday
:$
{user
.getBirStr()}<br>
</body
>
</html
>
EL–获取域中存储的值–List&Map集合
<%@ page
import="cn.itcast.domain.User" %>
<%@ page
import="java.util.Date" %>
<%@ page
import="java.text.SimpleDateFormat" %>
<%@ page
import="java.util.ArrayList" %>
<%@ page
import="java.util.Map" %>
<%@ page
import="java.util.HashMap" %><%--
Created by IntelliJ
IDEA.
User
: 联想
Date
: 2020/10/4
Time
: 17:22
To change
this template use File
| Settings
| File Templates
.
--%>
<%@ page contentType
="text/html;charset=UTF-8" language
="java" %>
<html
>
<head
>
<title
>通过
EL表达式获取数据
</title
>
</head
>
<body
>
<%
User user
= new User("张三", 20, new Date());
request
.setAttribute("user",user
);
ArrayList arrayList
= new ArrayList();
arrayList
.add("123");
arrayList
.add(user
);
request
.setAttribute("list",arrayList
);
Map map
= new HashMap();
map
.put("n","456");
map
.put("user",user
);
request
.setAttribute("map",map
);
%>
name
:$
{requestScope
.user
.name
}<br
>
age
:$
{user
.age
}<br
>
birthday
:$
{user
.birthday
.year
}-$
{user
.birthday
.year
}-$
{user
.birthday
.month
}-$
{user
.birthday
.day
}<br
>
birthday
:$
{user
.getBirStr()}<br
>
<h3
>list
</h3
>
$
{list
[0]}<br
>
$
{list
[1].name
}<br
>
<h3
>map
</h3
>
$
{map
.n
}<br
>
$
{map
["n"]}<br
>
$
{map
.user
.name
}<br
>
</body
>
</html
>
转载请注明原文地址:https://blackberry.8miu.com/read-8948.html