首页 > 其他分享 >EL获取域中存储的值和获取域中存储的值对象值

EL获取域中存储的值和获取域中存储的值对象值

时间:2023-02-01 11:26:09浏览次数:34  
标签: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/xuche/p/17081770.html

相关文章

  • 优雅地在Chisel-BlackBox中添加二维数组端口
    论坛地址:https://ysyx.oscc.cc/forum/topic/229/%E4%BC%98%E9%9B%85%E5%9C%B0%E5%9C%A8chisel-blackbox%E4%B8%AD%E6%B7%BB%E5%8A%A0%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84......
  • Shell脚本
    Shell脚本属于弱类型编程语言,数据类型默认都是字符串类型弱类型编程语言,在定义变量的时候,不用主动声明改类型比如:Shell、Pythonshell.name=28或者name="jack"Pyt......
  • nlog.config 输出到ELK的配置
    <nlogautoReload="true"xmlns="http://www.nlog-project.org/schemas/NLog.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <variablename="appName"va......
  • 半个前端新手入门Electron的过程
    前言先说几句废话,本人是一名web后端开发,主语言是java,在学Electron之前,只会一点点HTML和JavaScript。本文讲的也是我学习Electron的过程,而非教程,请酌情参考。Ele......
  • RTMP录屏直播屏幕数据获取与MediaCodec编码
    目录前言RTMP直播实现流程视频采集——MediaProjection编码——MediaCodec音频采集——AudioRecordRTMP音频包数据RTMP视频数据前言本文介绍的是MediaProjection录屏、麦......
  • python selenium之JS滚动条处理
    在网页当中,页面存在滚动条,而你要操作的元素在当前屏幕可见区域之外。那么需要使用滚动条滚动到该元素处,然后再操作它。selenium当中的使用execute_script方法执行js语句来......
  • xml解析_Jsoup_Document对象、Element对象
    xml解析_Jsoup_Document对象Document:文档对象。代表内存中的dom树获取Element对象getElementByid(String id):根据id属性值获取唯一的element对象g......
  • Flume 组件(source、channel、sink)远程调试
    1.创建Maven工程2.编写所需要自定义组件的代码(以Source为例),打包放到服务器上3.添加ideaDebug配置4.在服务器上广播Debug端口[atguigu@hadoop102flume]$exportFLUME_JA......
  • Kafka中unclean.leader.election.enable参数的内涵
    Kafka中unclean.leader.election.enable参数的内涵官网说明:http://kafka.apache.org/documentation/#configuration参考上图,某种状态下,follower2副本落后leader副本很多,并且......
  • jsDOM操作之获取元素
    1 根据id名获取document.getElementById(idName)2根据标签名获取document.getElementsByTagName(tagName)//返回一个集合(类数组对象)从整个文档获取element.getElem......