<%@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>

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

  1. EL表达式获取数据

    EL 全名为Expression Language. EL主要作用 获取数据: •EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据.(某个web域 ...

  2. [javaEE] EL表达式获取数据

    jsp标签: <jsp:include> <jsp:forward> 实现请求转发 <jsp:param> 给上面的添加参数的 EL表达式: 1.获取变量数据 &l ...

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

    <h4>获取域对象中的值</h4><%    request.setAttribute("name", "射雕英雄传");     ...

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

    Session的追踪技术 已知Session是利用cookie机制的server端技术.当client第一次訪问资源时 假设调用request.getSession() 就会在server端创建一个由 ...

  5. javascript-使用el表达式获取后台传递的数据

      js获取后台数据 CreateTime--2017年5月26日16:14:14Author:Marydon 在js中使用el表达式的前提是:HTML引用js使用内联方式(即在JSP页面内部使用js ...

  6. EL表达式获取值栈数据

    ---------------------siwuxie095 EL 表达式获取值栈数据 1.导入 JSTL 相关包,下载链接: (1)http://tomcat.apache.org/taglibs ...

  7. EL表达式获取Map和List中的值

    EL表达式获取Map和List中的值   EL表达式取Map中的值: 当Map中是String,String时 后台servlet中: Map<String, String> map1 = ...

  8. EL表达式读取数据(在Map,javaBean,List)

    <%@page import="cn.hncu.domain.User"%><!--这里是进行导包--><%@ page language=" ...

  9. 转:el表达式获取map对象的内容 & js中使用el表达式 & js 中使用jstl 实现 session.removeattribute

    原文链接: ①EL表达式取Map,List值的总结 ②在jsp中使用el表达式通过键获得后台的一个map<Long,String>的值 ③在javascript中使用el表达式(有图有真相 ...

随机推荐

  1. JavaScript从数组中删除指定值元素的方法

    本文实例讲述了JavaScript从数组中删除指定值元素的方法.分享给大家供大家参考.具体分析如下: 下面的代码使用了两种方式删除数组的元素,第一种定义一个单独的函数,第二种为Array对象定义了一个 ...

  2. CSS代码实例:用CSS代码写出的各种形状图形

    一共收集整理了图形20个,比较实用,同时也为了熟悉CSS的代码.整合了一下,有错误欢迎指出. 1.正方形 #square { width: 100px; height: 100px; backgrou ...

  3. Fiddler 使用备忘

    快捷键 ctrl + f(session 查询,高亮) ctrl + x(清除所有 session) alt + q(定位到命令行,以下操作为命令行语句) help(查看帮助文档) select sc ...

  4. 51nod 简单的动态规划

    1006 最长公共子序列Lcs 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). ...

  5. 一张图看懂git push

    基本用法 上面的四条命令在工作目录.暂存目录(也叫做索引)和仓库之间复制文件. git add files 把当前文件放入暂存区域. git commit 给暂存区域生成快照并提交. git rese ...

  6. 重新注册IIS

    出现问题的原因是先装了.NET4.0,再装IIS造成 处理方法:管理员权限执行cmd, C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_reg ...

  7. 【转】Java面试题全集2.2(下)

    154.如何在Web项目中配置Spring的IoC容器? 答:如果需要在Web项目中使用Spring的IoC容器,可以在Web项目配置文件web.xml中做出如下配置: <context-par ...

  8. java-生成印章swing

    案例1 package com; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import j ...

  9. Ubuntu 14.04.4官方默认更新源sources.list

    Ubuntu 14.04.4官方默认更新源sources.list # deb cdrom:[Ubuntu LTS _Trusty Tahr_ - Release amd64 (20160217.1) ...

  10. hihoCoder 后缀数组 重复旋律

    #1403 : 后缀数组一·重复旋律 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为长度为 N 的数构成 ...