JSP EL 初接触
上一篇 /
下一篇 2009-03-05 22:01:27
/ 个人分类:Jsp之路
1、JSP EL起源于JSTL1.0,全名JSP Expression Language
Jsp EL 可以在jsp中使用,也可以在jstl中使用
JSP EL作用:
(1)减少jsp页面中java代码的数量;
(2)方便jsp的修改
2、Jsp EL的运算符
算术运算符:+ - * / div % mod
逻辑运算符:&& and || or ! not
关系运算符:== eq != ne > gt >= gq < lt <= le
条件运算符:a?b:c
空:empty
3、Jsp EL语法
JavaBean ${user.username} 可以级联获取对象
数组 ${address[0]}
List ${address[0]}
Map ${phone.home}
4、JSP EL内置对象
注意:在Jsp页面使用时,严格遵循大小写
(1)Jsp El的内置对象
变量名称
说明
pageScope
一个包含所有page scope范围的变量集合 (a java.util.Map)
requestScope
一个包含所有request scope范围的变量集合 (a java.util.Map)
sessionScope
一个包含所有session scope范围的变量集合 (a java.util.Map)
applicationScope
一个包含所有application scope范围的变量集合 (a java.util.Map)
param
一个包含所有请求参数的集合 (a java.util.Map),通过每个参数对应一个String值的方式赋值
paramValues
一个包含所有请求参数的集合 (a java.util.Map),通过每个参数对应一个String数组的方式赋值
header
一个包含所有请求的头信息的集合, (a java.util.Map) ,通过每个头信息对应一个String值的方式赋值
headerValues
一个包含所有请求的头信息的集合 (a java.util.Map) ,通过每个头信息的值都保存在一个String数组的方式赋值
cookie
一个包含所有请求的 cookie集合 (a java.util.Map), 通过每一个cookie(javax.servlet.http.Cookie)对应一个cookie值的方式赋值
initParam
一个包含所有应用程序初始化参数的集合(a java.util.Map) ,通过每个参数分别对应一个String值的方式赋值
pageContext
一个javax.servlet.jsp.PageContext类的实例, 用来提供访问不同的请求数据
(2)param \paramValues 是用来获取request中的参数和参数数组
(3)header \headerValues 是用来获取http包的header 和 header数组
(4)cookie 获取cookie
(5)initParam 获取web.xml中设置的值
(6)empty 是判断内容是否为空,比如String a="" ${empty(a)} 结果是true
5、可以设定Jsp不使用Jsp EL,有两种办法
(1)<%@ page IsELIgnored="true" %>
(2)<web-app....
<jsp-config>
<jsp-property-groud>
<url-pattern>*.jsp</
<el-ignored>true</
............
<cut>
JSP 内置对象和JSP EL内置对象
JSP九个内置对象:
Implicit Objects for Scriptlets (JSP Scriplets中的隐含对象) | Type (对应类型) | Scope (范围) | Some Useful Methods (see class or interface for others) (常用的方法) |
1 | request | Subclass of javax.servlet.ServletRequest | Request | getAttribute, getParameter, getParameterNames, getParameterValues, setAttribute |
2 | response | Subclass of javax.servlet.ServletResponse | Page | Not typically used by JSP page authors |
3 | pageContext | javax.servlet.jsp.PageContext | Page | findAttribute, getAttribute, getAttributesScope, getAttributeNamesInScope, setAttribute |
4 | session | javax.servlet.http.HttpSession | Session | getAttribute, getId, setAttribute |
5 | application | javax.servlet.ServletContext | Application | getAttribute, getMimeType, getRealPath, setAttribute |
6 | out | javax.servlet.jsp.JspWriter | Page | clear, clearBuffer, flush, getBufferSize, getRemaining |
7 | config | javax.servlet.ServletConfig | Page | getInitParameter, getInitParameterNames |
8 | page | java.lang.Object | Page | Not typically used by JSP page authors |
9 | exception | java.lang.Throwable | Page | getMessage, getLocalizedMessage, printStackTrace, toString |
JSP十一个用于EL表达式的隐含(内置)对象:
Implicit Objects for EL Expressions 用于EL表达式的隐含对象 | Type 类型 | Description 具体说明 |
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)). |
收藏
举报
TAG: