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>

EL表达式获取数据的方式的更多相关文章
- EL表达式获取数据
EL 全名为Expression Language. EL主要作用 获取数据: •EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据.(某个web域 ...
- [javaEE] EL表达式获取数据
jsp标签: <jsp:include> <jsp:forward> 实现请求转发 <jsp:param> 给上面的添加参数的 EL表达式: 1.获取变量数据 &l ...
- 在JSP页面用EL表达式获取数据
<h4>获取域对象中的值</h4><% request.setAttribute("name", "射雕英雄传"); ...
- JAVAWEB开发之Session的追踪创建和销毁、JSP具体解释(指令,标签,内置对象,动作即转发和包括)、JavaBean及内省技术以及EL表达式获取内容的使用
Session的追踪技术 已知Session是利用cookie机制的server端技术.当client第一次訪问资源时 假设调用request.getSession() 就会在server端创建一个由 ...
- javascript-使用el表达式获取后台传递的数据
js获取后台数据 CreateTime--2017年5月26日16:14:14Author:Marydon 在js中使用el表达式的前提是:HTML引用js使用内联方式(即在JSP页面内部使用js ...
- EL表达式获取值栈数据
---------------------siwuxie095 EL 表达式获取值栈数据 1.导入 JSTL 相关包,下载链接: (1)http://tomcat.apache.org/taglibs ...
- EL表达式获取Map和List中的值
EL表达式获取Map和List中的值 EL表达式取Map中的值: 当Map中是String,String时 后台servlet中: Map<String, String> map1 = ...
- EL表达式读取数据(在Map,javaBean,List)
<%@page import="cn.hncu.domain.User"%><!--这里是进行导包--><%@ page language=" ...
- 转:el表达式获取map对象的内容 & js中使用el表达式 & js 中使用jstl 实现 session.removeattribute
原文链接: ①EL表达式取Map,List值的总结 ②在jsp中使用el表达式通过键获得后台的一个map<Long,String>的值 ③在javascript中使用el表达式(有图有真相 ...
随机推荐
- rsyslog及logrotate小结
[root@node1 logrotate.d]# ls dracut haproxy httpd mcelog nginx ppp psacct syslog yum yum install n ...
- httpUrlConnection中文乱码
public void getFeiInfo(String sessionId) throws IOException{ //发送的请求参数,发送的格式也是Json的 String requestSt ...
- 用C#实现封装
用C#实现封装 1.属性对外公开类似于类的接口实现对字段的访问;2.字段为private只能在内部被直接访问,如果当属性为只读,那么可以将形参直接对字段赋值.(有没有更好的方法?);3.可以通过关键字 ...
- 【深入理解计算机系统02】ISA 与内存模型
第二篇:认识ISA(Instruction Set Architecture) 重要概念: [ISA] [IA-32]:Intel把32位x86架构的名称x86-32改称为IA-32,一种身边很常见的 ...
- 【转】C++之父:C++ 的五个普遍误解
文章三部分如下: 1.http://blog.jobbole.com/82460/ 2.http://blog.jobbole.com/82461/ 3.http://blog.jobbole.com ...
- IOS在自己网站发布APP(企业版$299上线流程)
最近刚上线一个企业内部应用,前期准备账号和后期上线过程发现网络上的资源不是非常全面,在这里写给大家分享一下我的发布过程 首先是企业账号的申请我们企业账号前前后后一共花了16天时间,由于公司各方面都非常 ...
- JQUERY 测验
1.下面哪种说法是正确的? 您的回答:jQuery 是 JSON 库 正确答案:jQuery 是 JavaScript 库 2.jQuery 使用 CSS 选择器来选取元素? 您的回答:错误 正确答案 ...
- JQurey
jQuery 是一个 JavaScript 库.极大地简化了 JavaScript 编程,很容易学习. jQuery 是一个 JavaScript 函数库. jQuery 库包含以下特性: HTML ...
- redis源码安装
#安装目录 mkdir -p /data/apps/redis cd /data/tgz wget http://download.redis.io/releases/redis-3.2.1.tar. ...
- node 常用命令
nvm nvm list 列出安装的node npm install -g cnpm --registry=https://registry.npm.taobao.org 安装cnpm npm i ...