您的位置:首页 > 编程语言 > Java开发

JavaEE EL表达式杂记(EL内置对象 EL隐式对象)

2013-11-01 00:57 561 查看
内置对象相关文档:

http://docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaij (Java EE 1.5)

http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html#wp71043 (Java EE 1.4)


Implicit Objects

The JSP expression language defines a set of implicit objects:

pageContext: The context for the JSP page. Provides access to various objects including:

servletContext: The context for the JSP page’s servlet and any web components contained in the same application. See Accessing
the Web Context.

session: The session object for the client. See Maintaining
Client State.

request: The request triggering the execution of the JSP page. See Getting
Information from Requests.

response: The response returned by the JSP page. See Constructing
Responses.

In addition, several implicit objects are available that allow easy access to the following objects:

param: Maps a request parameter name to a single value

paramValues: Maps a request parameter name to an array of values

header: Maps a request header name to a single value

headerValues: Maps a request header name to an array of values

cookie: Maps a cookie name to a single cookie

initParam: Maps a context initialization parameter name to a single value

Finally, there are objects that allow access to the various scoped variables described in Using
Scope Objects.

pageScope: Maps page-scoped variable names to their values

requestScope: Maps request-scoped variable names to their values

sessionScope: Maps session-scoped variable names to their values

applicationScope: Maps application-scoped variable names to their values

JSP 2.1 provides two EL resolvers to handle expressions that reference these objects: ImplicitObjectELResolver and ScopedAttributeELResolver.

A variable that matches one of the implicit objects is evaluated by ImplicitObjectResolver, which returns the implicit object. This resolver only handles expressions with a base of null.
What this means for the following expression is that the ImplicitObjectResolver resolves the sessionScope implicit object only. Once the implicit
object is found, the MapELResolver instance resolves the profile attribute because the profile object
represents a map.
${sessionScope.profile}


ScopedAttributeELResolver evaluates a single object that is stored in scope. Like ImplicitObjectELResolver, it also only evaluates expressions
with a base of null. This resolver essentially looks for an object in all of the scopes until it finds it, according to the behavior of PageContext.findAttribute(String).
For example, when evaluating the expression ${product}, the resolver will look for product in the page, request, session, and application scopes
and will return its value. If product is not found, null is returned.

When an expression references one of the implicit objects by name, the appropriate object is returned instead of the corresponding attribute. For example,${pageContext} returns the PageContext object,
even if there is an existing pageContext attribute containing some other value.

 

其他相关文档

http://jcp.org/aboutJava/communityprocess/final/jsr245/index.html  (Java Server Pages 2.1)

http://jcp.org/en/jsr/detail?id=341 (EL 3.0)

http://docs.oracle.com/javaee/7/api/javax/el/package-summary.html (JavaEE 7 EL3.0类文档)

http://docs.oracle.com/javaee/7/tutorial/doc/jsf-el.htm (Java EE 7教程 EL表达式)

http://docs.oracle.com/javaee/5/tutorial/doc/bnahl.html#bnaho (Java EE 5 Tutorial JSP中的对象)

JSP内置对象:

Creating Dynamic Content

You create dynamic content by accessing Java programming language object properties.

Using Objects within JSP Pages

You can access a variety of objects, including enterprise beans and JavaBeans components, within a JSP page. JSP technology automatically makes some objects available, and you can also create and access application-specific objects.

Using Implicit Objects
Implicit objects are created by the web container and contain information related to a particular request, page, session, or application. Many of the objects are defined by the
Java servlet technology underlying JSP technology and are discussed at length in

Chapter 4, Java Servlet Technology. The section
Implicit Objects explains how you access implicit objects using the JSP expression language.

Using Application-Specific Objects
When possible, application behavior should be encapsulated in objects so that page designers can focus on presentation issues. Objects can be created by developers who are proficient in the Java
programming language and in accessing databases and other services. The main way to create and use application-specific objects within a JSP page is to use JSP standard tags (discussed inJavaBeans
Components) to create JavaBeans components and set their properties, and EL expressions to access their properties. You can also access JavaBeans components and other objects in scripting elements, which are described inChapter 9,
Scripting in JSP Pages.

Using Shared Objects
The conditions affecting concurrent access to shared objects (described inControlling Concurrent
Access to Shared Resources) apply to objects accessed from JSP pages that run as multithreaded servlets. You can use the followingpage directive to indicate how a web container should dispatch multiple client requests:

<%@ page isThreadSafe="true|false" %>

When the isThreadSafe attribute is set totrue, the web container can choose to dispatch multiple concurrent client requests to the JSP page. This is thedefault
setting. If using true, you must ensure that you properly synchronize access to any shared objects defined at the page level. This includes objects created within declarations, JavaBeans components with page scope, and attributes of the page context
object (see
Implicit Objects).

If isThreadSafe is set to false, requests are dispatched one at a time in the order they were received, and access to page-level objects does not have to be controlled. However, you still must ensure that access is properly synchronized
to attributes of the application or session scope objects and to JavaBeans components with application or session scope. Furthermore, it is not recommended to setisThreadSafe to
false. The JSP page’s generated servlet will implement thejavax.servlet.SingleThreadModel interface, and because the Servlet 2.4 specification deprecatesSingleThreadModel, the generated servlet will contain deprecated code.


JSTL 入门: 表达式语言 http://www.ibm.com/developerworks/cn/java/j-jstl0211/  

http://docs.oracle.com/javaee/5/tutorial/doc/bnahl.html#bnaho (Java EE 5 Tutorial JSP中的对象)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: