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中的对象)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要创建一个新的 Maven 项目。然后,按照以下步骤进行配置: 1. 在 pom.xml 文件中添加以下依赖: ``` <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>org.apache.taglibs</groupId> <artifactId>taglibs-standard-impl</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>org.apache.taglibs</groupId> <artifactId>taglibs-standard-spec</artifactId> <version>1.2.5</version> </dependency> ``` 2. 在 web.xml 文件中添加以下配置: ``` <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <display-name>MyWebApp</display-name> <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <el-ignored>false</el-ignored> <pageEncoding>UTF-8</pageEncoding> <scripting-invalid>false</scripting-invalid> <isXml>false</isXml> <trimDirectiveWhitespaces>true</trimDirectiveWhitespaces> </jsp-property-group> </jsp-config> <listener> <listener-class>org.apache.jasper.servlet.JasperListener</listener-class> </listener> </web-app> ``` 3. 在 IDEA 中创建 JSP 文件,并在其中使用 EL 表达式和 JSTL 标签库。 以上步骤可以让你用 IDEA 创建一个支持 EL 表达式和 JSTL 的项目。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值