JSP Expression Language

Source: Internet
Author: User

JSP Expression Language (2)

Point operators and index operators can be used to access map. For example, the following two El expressions return the value corresponding to the key named mykey:

However, there is a small difference between the two: if the key name contains characters that can confuse El, you cannot use the dot operator. For example, if $ {header ["User-Agent"]} is used, there is no problem, but $ {header. the User-Agent} error occurs because the break number between the user and the agent in the second expression is parsed as a minus sign. Unless there is a variable named agent, and header. User and agent are both null, according to the El specification documentation, the $ {null-null} result is zero. The first expression may return zero. If the map key name contains a vertex, you may encounter different but more serious problems. For example, you can use $ {Param ["My. Par"]} normally, and $ {Param. My. Par} may get null. This will be a serious problem, because null is a possible valid result. We recommend that you use square brackets in all scenarios and forget these questions.

Like JSP, El also contains implicit objects, as shown in Table 2-7.

Table 2-7 El implicit objects

Object

Description

Pagecontext

JSP page context. In particular, pagecontext.

Reference obtained by servletcontext and implicit in JSP

Type Variable Application references to the same object.

Similarly, pagecontext. Session, etc.

Price for sessions in JSP, pagecontext.

Request is equivalent to the request in JSP,

Pagecontext. response is equivalent

Response in JSP

Param

Map the request parameter name to its first value.

Paramvalues

Map the request parameter name to an array containing its values.

Header

Map the request header name to its first value.

Headervalues

Map the request header name to an array containing its values

Cookie

Map the cookie name to a unique cookie.

Initparam

Map the context initialization parameter to its value

Pagination

Map the page-scoped variable names to their values

Requestscope

Map the names of requset-scoped variables to their values.

Sessionscope

Map the seesion-scoped variable names to their values.

Applicationscope

Map application-scoped variable names to their values

Note that JSP script variables are invalid in El expressions.

You may have noticed that El does not contain any methods to declare variables. In El expressions, you can use the jstl Core Action C: Set (as described in the next section) or the variables set by the scope attribute (scoped attributes. For example, the following definitions allow you to use the El expression $ {xyz }.

However, you must pay more attention to the scope. C: The set variable and the attribute in pagecontext are the same variable. That is to say, C: Set defines an attribute in the page context. The attributes in sessioncontext are different from other variables, and you cannot access them in $ {xyz} because they "hide" the attributes with the same name in the page context. To access the session attribute, you must prefix sessionscope before the attribute name, such as $ {sessionscope. xyz. If you do not specify a scope, El will first search for attributes in the page, then request, session, and finally apply scope.

Note that El expressions cannot be nested. An expression like ${expr1 [$ {expr2}]} is invalid.

You can combine several El expressions and additional texts into a composite expression, as shown in the following example:

However, you cannot mix $ {}and # {} formats #{}.

From: http://book.51cto.com/art/200909/150189.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.