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表达式(有图有真相 ...
随机推荐
- Python-05-常用模块
sys模块 # sys.argv # 在执行程序的时候可以给程序传参数,例如类似执行nginx检测配置文件语法功能的命令, nginx -t # mode_sys.py import sys prin ...
- C++学习笔记(2)
本学习笔记是C++ primer plus(第六版)学习笔记.是C++学习笔记(1)的后续.复习C++基础知识的可以瞄瞄. 转载请注明出处http://www.cnblogs.com/zrtqsk/p ...
- haproxy 新手上路
apache.nginx之类的反向代理(转发)功能,通常只能用于http协议,其它协议就不好使了(注:nginx据说商业版的,支持tcp协议了). haproxy可以弥补这方面的不足,haproxy支 ...
- Memcached telnet端命令
Command Description Example get Reads a value get mykey set Set a key unconditionally set mykey 0 60 ...
- C++ URLDecode和URLEncode实现——仅限gb2312,非utf8
转载--http://blog.163.com/zhangjie_0303/blog/static/9908270620148251658993/ #include <iostream> ...
- bzoj1588
splay #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...
- js-JavaScript高级程序设计学习笔记21 改善JavaScript性能的方法
第24章 最佳实践 1.性能 1.避免全局查找 将在一个函数中会用到多次的全局对象保存在局部变量.比如多次使用document.getElement...,可以首先var doc=document,把 ...
- Python 面向对象 基础
编程范式概述:面向过程 和 面向对象 以及函数式编程 面向过程:(Procedure Oriented)是一种以事件为中心的编程思想. 就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现 ...
- python面向对象进阶(八)
上一篇<Python 面向对象初级(七)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...
- HTML案例—很讨巧的一种js+css制作hover模式展示二级菜单方法
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>利 ...