EL表达式获取数据的方式

<%@page import="cn.jiemoxiaodi.domain.Person"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP ‘demo1.jsp‘ starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
    <h3>传统方式获得的值</h3>
    <%
        pageContext.setAttribute("pageName", "pagVal");
        request.setAttribute("reqName", "reqVal");
        session.setAttribute("sessionName", "sessionVal");
        application.setAttribute("appName", "appVal");
    %>
    <%=pageContext.getAttribute("pageName")%>
    <%=request.getAttribute("reqName")%>
    <%=session.getAttribute("sessionName")%>
    <%=application.getAttribute("appName")%>
    <H3>使用EL表达式获得的值</H3>
    ${pageScope.pageName} ${requestScope.reqName}
    ${sessionScope.sessionName} ${applicationScope.appName} 简写 ${pageName}
    ${reqName}

    <h3>使用EL获得集合的值</h3>
    <%
        String[] str = new String[] { "张三", "lisi", "招六" };
        pageContext.setAttribute("str", str);
    %>
    ${str[0]} ${str[1]} ${str[2]}
    <h3>使用EL获得List集合的值</h3>
    <%
        List<String> tempList = new ArrayList<String>();
        tempList.add("张三");
        tempList.add("李四");
        tempList.add("王武");
        pageContext.setAttribute("ArrayLists", tempList);
    %>
    ${ArrayLists[0]} ${ArrayLists[1]} ${ArrayLists[2]}
    <h3>使用EL获得Map集合的值</h3>
    <%
        Map<String, String> tempMap = new HashMap<String, String>();
        tempMap.put("first", "zhangfirst");
        tempMap.put("second", "two");
        tempMap.put("third", "three");
        tempMap.put("four", "four");
        pageContext.setAttribute("Maps", tempMap);
    %>
    ${Maps.first} ${Maps.second} ${Maps.third} ${Maps.four}

    <h3>使用EL获得对象的值</h3>
    <%
        Person p = new Person();
        p.setName("小红");
        p.setAge(22);
        pageContext.setAttribute("p", p);
    %>
    ${p.name} ${p.age}
    <h3>使用EL获得集合中对象的数据</h3>
    <%
        List<Person> pList = new ArrayList<Person>();
        pList.add(new Person("张三", 22));
        pList.add(new Person("李四", 44));
        pageContext.setAttribute("pList", pList);
    %>
    ${pList[0].name} ${pList[0].age} ${pList[1].name} ${pList[1].age}

</body>
</html>

时间: 2024-08-01 22:42:46

EL表达式获取数据的方式的相关文章

EL表达式获取数据

EL 全名为Expression Language. EL主要作用 获取数据: •EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据.(某个web域 中的对象,访问javabean的属性.访问list集合.访问map集合.访问数组) 执行运算: •利用EL表达式可以在JSP页面中执行一些基本的关系运算.逻辑运算和算术运算,以在JSP页面中完成一些简单的逻辑运算.${user==null} 获取web开发常用对象 •EL 表达式定义了一些隐式对象,

[javaEE] EL表达式获取数据

jsp标签: <jsp:include> <jsp:forward> 实现请求转发 <jsp:param> 给上面的添加参数的 EL表达式: 1.获取变量数据 <% String name="陶士涵"; pageContext.setAttribute("name",name); %> 你好,${name} 2.获取数组数据 <% String[] names={"陶士涵","张三&

黑马day06 EL表达式获取数据

获取数据: 使用中括号的地方都可以使用点号替代,除了中括号中是数字或者中括号中包含特殊字符(-.)的情况除外 在中括号中如果不用双引号引起来则是变量,先找变量的值再拿变量的值使用.如果用双引号则是常量,直接使用常量的值 ~获取常量 字符串/数字/布尔类型,直接写在el表达式中,el直接进行输出 ~获取域中的变量 如果el中写的是一个变量的名,则el会调用pageContext的findAttribute方法,在四大作用域中以给定的名字找对应的属性值,找到后进行输出,如果四个域中都找不到,什么都不

在JSP页面用EL表达式获取数据

<h4>获取域对象中的值</h4><%    request.setAttribute("name", "射雕英雄传");    application.setAttribute("name", "鹿鼎记");%>${requestScope.name } ${applicationScope.name } <h4>获取数组中的值</h4><%    Strin

JAVAWEB开发之Session的追踪创建和销毁、JSP详解(指令,标签,内置对象,动作即转发和包含)、JavaBean及内省技术以及EL表达式获取内容的使用

Session的追踪技术 已知Session是利用cookie机制的服务器端技术,当客户端第一次访问资源时 如果调用request.getSession() 就会在服务器端创建一个由浏览器独享的session空间,并分配一个唯一且名称为JSESSIONID的cookie发送到浏览器端,如果浏览器没有禁用cookie的话,当浏览器再次访问项目中的Servlet程序时会将JSESSIONID带着,这时JSESSIONID就像唯一的一把钥匙  开启服务器端对应的session空间,进而获取到sessi

JAVAWEB开发之Session的追踪创建和销毁、JSP具体解释(指令,标签,内置对象,动作即转发和包括)、JavaBean及内省技术以及EL表达式获取内容的使用

Session的追踪技术 已知Session是利用cookie机制的server端技术.当client第一次訪问资源时 假设调用request.getSession() 就会在server端创建一个由浏览器独享的session空间,并分配一个唯一且名称为JSESSIONID的cookie发送到浏览器端,假设浏览器没有禁用cookie的话,当浏览器再次訪问项目中的Servlet程序时会将JSESSIONID带着.这时JSESSIONID就像唯一的一把钥匙  开启server端相应的session空

关于页面EL表达式获取list集合、元素相关

之前做项目(裁判文书信息修改)的时候,遇到一些问题 1.数据树结构显示失败 页面数据显示不出来树结构,原因是因为缺少调用接口方法  ztreeNodes1 = getDeptREmp(oid); 2.json拼接的问题 //之前的拼接方法是: jsonstr = "{\"oid\":\""+oid+"\"}"; //拼接json ,\"dyfs\":\""+dyfs+"\&qu

SSH 框架controller向jsp传递List jsp中使用el表达式获取

mvc可以使用ModelAndViev传递数据选择跳转的视图 controller中的代码, 把一个模拟的表单studentListSimulate传给ModelAndView @RequestMapping("/detial") public Model showStudentDetial(Model mod) { ModelAndView mav = new ModelAndView(); mav.addObject("studentListSimulate",

MFC获取数据的方式

假设输入框ID是:ID_NUMBER1,ID_NUMBER2,ID_NUMBER3. 获取数据的方式是: int number1,number2,number3; number1 = GetDlgItemInt(ID_NUMBER1); number2 = GetDlgItemInt(ID_NUMBER2); number3 = number1 + number2; SetDlgItemInt(ID_NUMBER3,number3); 将数据3设置在输入框三中.