首页 > 其他分享 >EL_获取域中存储的值以及对象值

EL_获取域中存储的值以及对象值

时间:2022-12-22 20:55:14浏览次数:31  
标签:EL 存储 return name age 获取 birthday public

 

EL_获取域中存储的值

1.获取值:

  1.el表达式只能从域对象获取值

  2.语法:

    1.${域名称.键名}:从指定域中获取指定键的值

      域名称:

        1.pageScope        -- > pageContext

        2.requestScope    -- > request

        3.sessionScope    -- > session

        4.applicationScope     -- >application(ServletContext) 

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
    <title>el获取域中的数据</title>
</head>
<body>


    <%
        //域中存储数据
        request.setAttribute("name", "张三");
        session.setAttribute("age", "23");
    %>

<h3>el获取值</h3>
${requestScope.name}
${sessionScope.age}

</body>
</html>

2.${键名}:表示依次从最小的域中查找是否有该键对应的值,直到找到为止

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
    <title>el获取域中的数据</title>
</head>
<body>


    <%
        session.setAttribute("name", "李四");

        //域中存储数据
        request.setAttribute("name", "张三");
        session.setAttribute("age", "23");
    %>

<h3>el获取值</h3>
${requestScope.name}
${sessionScope.age}

${sessionScope.name}

</body>
</html>

 

 

 

EL_获取域中存储对象值

1.获取对象:List集合,Map集合的值

  1.对象:${域名称.键名.属性名}

    本质上会去调用对象的getter方法

User实体类

package com.example.domain;

import java.text.SimpleDateFormat;
import java.util.Date;

public class User {

        private String name;
        private int age;
        private Date birthday;

    /**
     * 逻辑视图
     * @return
     */
   public String getBitStr(){
       if (birthday != null){
           //1.格式化日期对象
           SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
           //2.返回字符串即可
           return format.format(birthday);
       }else {
           return "";
       }
   }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", 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;
    }
}

jsp页面:

<%@ page import="com.example.domain.User" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
    <title>获取数据</title>
</head>
<body>

    <%
        User user = new User();
        user.setName("张三");
        user.setAge(23);
        user.setBirthday(new Date());

        request.setAttribute("u", user);
    %>

<h3>el获取对象中的值</h3>
${requestScope.u}<br>

<%--
    * 通过的是对象的属性来获取
           setter或getter方法,去掉set或get,在将剩余部分,首字母变为小写
           setName -- > Name -- > name
--%>

    ${requestScope.u.name}<br>
    ${u.age}<br>
    ${u.birthday}<br>
    ${u.birthday.month}<br>

    ${u.bitStr}<br>
</body>
</html>

 

标签:EL,存储,return,name,age,获取,birthday,public
From: https://www.cnblogs.com/qihaokuan/p/16999561.html

相关文章

  • 解锁通达信金融终端Level-2功能
    外挂方式,不修改原程序。   ......
  • EL概述以及运算符
    EL概述以及运算符1.概念:Expression Language:表达式语言2.作用:替换和简化jsp页面java代码的编写3.语法:${表达式}4.注意:jsp默认支持el表达式。如果要忽略表达式......
  • Vue中 TodoList 示例: 浏览器本地存储、自定义事件
    Vue中TodoList示例:浏览器本地存储、自定义事件1:界面展示情况2:源代码vue.config.jsconst{defineConfig}=require('@vue/cli-service')module.exports=defineConf......
  • Linux系统入门-Shell命令
    linux中的shellLinux中的shell,是指一个面向用户的命令接口,表现形式就是一个可以由用户录入的界面,这个界面也可以反馈运行信息。shell在Linux中的存在形式由于Linux不同于Win......
  • VC 读写Excel (第三方类CSpreadSheet)
    1. 用VC6新建一个基于对话框的项目;2. 添加 CSpreadSheet.h,CSpreadSheet.cpp到项目中;3. 在C*Dlg.h 中添加 : #include "CSpreadSheet.h"4. 添加对应的读写函数5. 读......
  • vue中读取本地Excel文件
    readExcelFileconstXLSX=require('xlsx')constpath="./file/file.xlsx"//放在public目录下的文件可以直接访问axios.get(path,{responseType:'arraybuffer'......
  • vue获取选中日期的日、周、月、季、年起始结束时间
    dealDate:日期处理(type类型,date日期)constmoment=require('moment');if(type==="0"){returndate+"00:00:00#"+date+"23:59:59";}elseif(type......
  • 【Python】羊毛获取小工具
    前言最近沉迷薅羊毛,然后想第一时间得到新的消息。不过说实话第一时间是不存在的,除非跟商家直接对接。于是乎只能靠微博啊,企鹅群等,看别人发的新信息了。那么做一个简单......
  • [Linux Kernel 源码分析] 通过vconfig配置vlan的系统调用/驱动流程分析
    ByYuCloud(蓝天上的云℡-博客园https://www.cnblogs.com/yucloud/)转载请注明出处vconfig源码分析vlan/vconfig.catmaster·Distrotech/vlan(github.com)h......
  • 不同存储资源的应用场景及优缺点介绍
    容器应用应当根据应用系统的特点,综合考虑容器应用对存储类型、存储性能及数据高可用等方面的要求,选择最适合的存储资源类型。常见的存储资源应用场景包括三类:将存储挂载在外......