EL内置对象
- 读取JSP页面作用范围的隐含对象:作用范围从小到大分别是:pageScope -> requestScope -> sessionScope -> applicationScope。一般有两种调用方式:${sessionScope.keyName},如果keyName包含JSP不能正确识别的特殊字符,则需要用${sessionScope['keyName']}这种方式才能获得相应的值。如果直接这样调用${keyName},则JSP会根据作用范围的大小从小到大分别去查找,直到找到为止。
- 读取request请求报头的信息:使用header即能获得报头名称对应的报头值,如果报头名对应的值是一个数组,则要使用headerValues来获得取。如${header.host},${header['user-agent']},${headerValues.cookie}
- 读取cookie的隐含对象:如果要读取客户端传输过来的数据,则要用到cookie隐含对象来读取。例如:${cookie.userName.value},如果有多个名为userName的cookie对象,则要使用headerValues来读取,因为cookie是报头的一部分。
- 读取客户端传送过来的参数:如果要在JSP页面中直接读取客户端参数,可以这样获得${param.paramName} ,如果参数为一数组,则应该要这样读取,${paramValues.paramName}
- 读取应用上下文的初始化参数:如${initParam.paramName}来获得。
EL表达式的隐含对象
EL表达式的隐含对象 Type 具体说明 pageContext javax.servlet.jsp.PageContext The context for the JSP page.
Provides access to various
objects, including servletContext, session, request,
and response.pageScope java.util.Map Maps page-scoped variable names
to their values.requestScope java.util.Map Maps request-scoped variable
names to their values.sessionScope java.util.Map Maps session-scoped variable
names to their values.applicationScope java.util.Map Maps application-scoped variable
names to their values.param java.util.Map Maps a request parameter to a
single String parameter value
(obtained by calling
ServletReqwuest.getParameter
(String name)).paramValues java.util.Map Maps a request parameter name to
an array of String values for
that parameter name (obtained by
calling
ServletRequest.getParameterValues
(String name)).header java.util.Map Maps a request header name to a
single String header value
(obtained by calling
ServletRequest.getHeader(String
name)).headerValues java.util.Map Maps a request header name to an
array of String values for that
header (obtained by calling
ServletRequest.getHeaders
(String)).coookie java.util.Map Maps a cookie name to a single
Cookie object. Cookies are
retrieved according to the
semantics of
HttpServletRequest.getCookies().
If the same name is shared by
multiple cookies, an
implementation must use the first
one encountered in the array of
Cookie objects returned by the
getCookies() method. However, the
ordering of cookies is currently
unsspecified in the Servlet specification.initParam java.util.Map Maps a context initialization
parameter name to a String
parameter value (obtained by
calling
ServletContext.getInitparameter
(String name)).