`
lgh06
  • 浏览: 55134 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

内置对象相关文档:

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:

  • 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 inUsing 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:ImplicitObjectELResolverandScopedAttributeELResolver.

A variable that matches one of the implicit objects is evaluated byImplicitObjectResolver, which returns the implicit object. This resolver only handles expressions with a base ofnull. What this means for the following expression is that theImplicitObjectResolverresolves thesessionScopeimplicit object only. Once the implicit object is found, theMapELResolverinstance resolves theprofileattribute because theprofileobject represents a map.

${sessionScope.profile}

ScopedAttributeELResolverevaluates a single object that is stored in scope. LikeImplicitObjectELResolver, it also only evaluates expressions with a base ofnull. This resolver essentially looks for an object in all of the scopes until it finds it, according to the behavior ofPageContext.findAttribute(String). For example, when evaluating the expression${product}, the resolver will look forproductin the page, request, session, and application scopes and will return its value. Ifproductis not found,nullis 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 thePageContextobject, even if there is an existingpageContextattribute 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 Chapter4, 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 inChapter9, 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中的对象)

版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics