JavaWeb EL表达式

 1 package com.study.test;
 2 
 3 public class User {
 4     public String name;
 5 
 6     public User(String name, Integer age) {
 7         this.name = name;
 8         this.age = age;
 9     }
10 
11     public String getNum() {
12         return "Xhhhhh";
13     }
14 
15     @Override
16     public String toString() {
17         return "User{" +
18                 "name='" + name + '\'' +
19                 ", age=" + age +
20                 '}';
21     }
22 
23     public void setName(String name) {
24         this.name = name;
25     }
26 
27     public Integer getAge() {
28         return age;
29     }
30 
31     public void setAge(Integer age) {
32         this.age = age;
33     }
34 
35     private Integer age;
36 }
<%@ page import="com.study.test.User" %><%--
  Created by IntelliJ IDEA.
  User: a
  Date: 2021/4/28
  Time: 21:33
  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>
<%
    //    pageContext.setAttribute("names", "pagecontext");
//    request.setAttribute("names", "reques");
//    session.setAttribute("names", "session");
//    application.setAttribute("names", "application");
    User user = new User("xx", 78);
    pageContext.setAttribute("name", user);

%>
<%--&lt;%&ndash;指定作用域&ndash;%&gt;--%>
<%--${sessionScope.names}--%>
<table>
    <tr>
        <th>姓名</th>
        <th>年龄</th>

    </tr>
    <tr>
        <%--反射反射 与堆无关 el找的是方法区 只要有get就行 不区分大小写--%>
        <th>${name.num}</th>
        <th>${name.age}</th>
    </tr>
</table>
</body>
</html>
反射反射 与堆无关 el找的是方法区 只要有get就行 不区分大小写
posted @ 2021-04-28 22:09  冯方  阅读(40)  评论(0)    收藏  举报