---
title: "EL隐含对象"
author: "zcbbupt"
date: "2011-05-25T16:15:43Z"
tags: ["JSP", "Web", "XML"]
categories: ["互联网"]
slug: "el"
draft: false
lastmod: "2011-05-25T16:16:41Z"
id: 1058356
url: "https://zcbbupt.iteye.com/blog/1058356"
---

在EL中提供有11个隐含对象，其中除了pageContext隐含对象对应PageContext之外，其他隐含对象都对应Map类型。

1、PageContext隐含对象

对应于PageContext类型，PageContext本身就是个JavaBean，只要是get**()方法，就可以用${pageContext.xxx}来取得。

2、与属性范围相关的隐含对象

与属性范围相关的EL隐含对象有pageScope、ruquestScope、sessionScope与applicationScope。分别可以取得使用JSP隐含对象pageContext、request、session与application的setAtrribute()方法所设置的属性对象。如果不使用EL隐含对象制定范围，则默认从pageScope的属性开始寻找。

注：EL隐含对象pageScope、requestScope、sessionScope和applicationScope仅仅代表作用范围。

3、与请求参数相关的隐含对象

与请求参数相关的EL隐含对象有param与paramValues。举例来说，${param.user}的作用相当于<%=ruquest.getParameter("user")%>。

4、与标头（Header）相关的隐含对象

如果要取得用户请求的表头数据，则可以使用header或headerValues隐含对象。例如${header["User-Agent"]}相当于<%= request.getHeader("User-Agent")%>.

5、cookie隐含对象

cookie隐含对象可以用来取得用户Cookie设置值。如果Cookie中设置了username属性，则可以使用${cookie.username}来取得值。

6、初始参数隐含对象

initParam可以用来取得web.xml中设置的SeveletContext初始化参数，也就是在<context-param>中设置的初始化参数。例如，${initParam.initCount}的作用相当于<%= servletContext.getInitParameter("initCount")%>。