EL表达式-例子
2015-11-27 22:16
232 查看
<%@page import="java.util.*"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@page import="com.amos.model.*"%> <%@ page isELIgnored="false"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>el表达式学习</title> </head> <body> 第一种,简单取值: <% String data = "hi,amos!"; request.setAttribute("data", data); %> ${data} <br> 第二种,从bean中取值: <% Person p = new Person(); p.setName("amosli"); session.setAttribute("person", p); %> ${person.name} <br> <%=((Person) session.getAttribute("person")).getName()%><br> 第三种:从复杂bean中取值: <% Person person1 = new Person(); Address a = new Address(); a.setCity("上海"); person1.setAddress(a); application.setAttribute("p1", person1); %> ${p1.address.city} <br> 第四种:从集合中取值: <% List list = new ArrayList(); list.add(new Person("amos")); list.add(new Person("li")); list.add(new Person("amosli")); list.add(new Person("hi")); list.add(new Person("hi_amos")); application.setAttribute("personlist", list); %> ${personlist[0].name } <br> <% Map map = new HashMap(); map.put("aa", new Person("aaaa")); map.put("cc", new Person("cccc")); map.put("dd", new Person("dddd")); map.put("ee", new Person("eeee")); map.put("11", new Person("111")); request.setAttribute("map", map); %> ${map.dd.name }<br> <%-- ${map.11.name } 一般情况下用点号进行取值,如果点号取不出来值,那么可以用[]来代替. --%> ${map['11'].name }<br> 获取当前应用的名称: ${pageContext.request.contextPath } </body> </html>
相关文章推荐
- Java保留小数问题
- git常用命令
- iOS基础知识:文件流以及文件操作中的主要函数
- iOS应用程序拨打电话
- android Camera架构浅析
- 手机摄像头介绍及其参数配置
- 生成函数学习笔记
- Gabor滤波器的生成
- 关于游戏中的分享之ShareSDK的研究
- Linux下安装qtcreator部分问题解决
- MySQL时间操作
- 设置MyEclipse开发项目时使用的JDK
- java代理理解(一)
- 关于将本地项目push到github发生冲突的问题
- 样本方差与总体方差
- 使用指向指针的指针对字符串排序
- android 圆角
- android 圆角
- java环境变量配置
- unity3D制作血条跟随的研究