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)
(常用的方法)
1requestSubclass of javax.servlet.ServletRequestRequestgetAttribute, getParameter, getParameterNames, getParameterValues, setAttribute
2responseSubclass of javax.servlet.ServletResponsePageNot typically used by JSP page authors
3pageContextjavax.servlet.jsp.PageContextPagefindAttribute, getAttribute, getAttributesScope, getAttributeNamesInScope, setAttribute
4sessionjavax.servlet.http.HttpSessionSessiongetAttribute, getId, setAttribute
5applicationjavax.servlet.ServletContextApplicationgetAttribute, getMimeType, getRealPath, setAttribute
6outjavax.servlet.jsp.JspWriterPageclear, clearBuffer, flush, getBufferSize, getRemaining
7configjavax.servlet.ServletConfigPagegetInitParameter, getInitParameterNames
8pagejava.lang.ObjectPageNot typically used by JSP page authors
9exceptionjava.lang.ThrowablePagegetMessage, getLocalizedMessage, printStackTrace, toString
 
JSP十一个用于EL表达式的隐含(内置)对象:
Implicit Objects for EL
Expressions
用于EL表达式的隐含对象
Type
类型
Description
具体说明
pageContextjavax.servlet.jsp.PageContextThe context for the JSP page. Provides access to various objects, including servletContext, session, request, and response.
pageScopejava.util.MapMaps page-scoped variable names to their values.
requestScopejava.util.MapMaps request-scoped variable names to their values.
sessionScopejava.util.MapMaps session-scoped variable names to their values.
applicationScopejava.util.MapMaps application-scoped variable names to their values.
paramjava.util.MapMaps a request parameter to a single String parameter value (obtained by calling ServletReqwuest.getParameter(String name)).
paramValuesjava.util.MapMaps a request parameter name to an array of String values for that parameter name (obtained by calling ServletRequest.getParameterValues(String name)).
headerjava.util.MapMaps a request header name to a single String header value (obtained by calling ServletRequest.getHeader(String name)).
headerValuesjava.util.MapMaps a request header name to an array of String values for that header (obtained by calling ServletRequest.getHeaders(String)).
coookiejava.util.MapMaps 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.
initParamjava.util.MapMaps a context initialization parameter name to a String parameter value (obtained by calling ServletContext.getInitparameter(String name)).

TAG:

 

评分:0

我来说两句

Open Toolbar