The definition and use of the El of JSP in Java

Source: Internet
Author: User
Tags sessions

1. Definition:

EL (Expression Language) is designed to make jsps easier to write. The expression language is inspired by the ECMAScript and XPath expression languages, which provide a way to simplify expressions in the JSP, simplifying the code for the JSP.

2.

1. Syntax structure ${expression}2, [] with. Operator El provides "." and "[]" operators to access data. When the name of the property to be accessed contains some special characters, such as. Or-such as symbols that are not letters or numbers, be sure to use "[]". For example: ${user. My-name} should be changed to ${user["My-name"} if you want to dynamically fetch values, you can use "[]" to do, and "." cannot be dynamically evaluated. For example: ${sessionscope.user[data]} where data is a variable 3, the variable el Access variable data method is very simple, for example: ${username}. It means to take out a variable whose name is username in a range. Because we do not specify a range of username, it will be searched sequentially from page, Request, Session, application range. If the way to find username, direct callback, no longer continue to find, but if all the scope is not found, the return null. is a JSP expression language that defines the following text that can be used in an expression:
True and False
Similar to Java. Can contain any positive or negative numbers, such as 24,-45, 567
Similar to Java. Can contain any positive or negative floating-point numbers, such as -1.8E-45, 4.567
Any string that is qualified by single or double quotation marks. For single quotes, double quotes, and backslashes, use a backslash character as an escape sequence. It is important to note that single quotes do not need to be escaped if double quotes are used at both ends of the string.
Null
2. The operator JSP expression language provides the following operators, most of which are common operators in Java:
Terminology definition
Arithmetic type +,-(two Yuan), *,/, Div,%, mod,-(one yuan)
Logic type And, &&, or, | | 、!、 not
Relationship Type = =, EQ,! =, NE, <, lt, >, GT, <=, le, >=, GE. Can be compared with other values, or with Boolean, String, Integer, or floating-point literals.
Empty The empty empty operator is a prefix operation that can be used to determine whether a value is empty.
Conditional type A? B:c. Assigns a value B or C according to the result of a assignment.
3. The implicit object JSP expression language defines a set of implicit objects, many of which are available in JSP Scriplet and expressions:
PageContext The context of the JSP page. It can be used to access JSP implicit objects such as requests, responses, sessions, outputs, ServletContext, and so on. For example, ${pagecontext.response} assigns a value to a page's response object.
In addition, several implicit objects are available that allow easy access to the following objects:
Terminology definition
Param Maps the request parameter name to a single string parameter value (obtained by calling Servletrequest.getparameter (string name). The GetParameter (String) method returns a parameter with a specific name. The expression ${param. Name} is equivalent to Request.getparameter (name).
Paramvalues Map the request parameter name to a numeric array (obtained by calling Servletrequest.getparameter (String name). It is very similar to the Param implicit object, but it retrieves an array of strings instead of a single value. The expression ${paramvalues. Name} is equivalent to Request.getparamtervalues (name).
Header Map the request header name to a single string header value (obtained by calling Servletrequest.getheader (string name). The expression ${header. Name} is equivalent to Request.getheader (name).
Headervalues Map the request header name to a numeric array (obtained by calling Servletrequest.getheaders (String)). It is very similar to an implicit object. The expression ${headervalues. Name} is equivalent to Request.getheadervalues (name).
Cookies Maps the cookie name to a single Cookie object. A client request to the server can obtain one or more cookies. The expression ${cookie. Name. Value} returns the first cookie value with a specific name. If the request contains more than one cookie with the same name, you should use the ${headervalues. Name} expression.
Initparam The context initialization parameter name is mapped to a single value (obtained by calling Servletcontext.getinitparameter (String name).
In addition to the above two types of implicit objects, there are also objects that allow access to a wide range of variables, such as Web contexts, sessions, requests, and pages:
Terminology definition
Pagescope Maps the variable name of a page range to its value. For example, an EL expression can use ${pagescope.objectname} to access a page-scoped object in a JSP, and you can use ${pagescope. ObjectName. AttributeName} to access the properties of an object.
Requestscope Map the variable name of the request scope to its value. The object allows access to the properties of the requested object. For example, an EL expression can use ${requestscope. ObjectName} to access an object of a JSP request scope, and you can use ${requestscope. ObjectName. AttributeName} to access the properties of the object.
Sessionscope Maps a session-scoped variable name to its value. The object allows access to the properties of the session object. Example: ${sessionscope. Name}
Applicationscope Maps application-scoped variable names to their values. The implicit object allows access to application-scoped objects.
Special emphasisEdit1. Note that when an expression references one of these objects by name, the corresponding object is returned instead of the corresponding of the Properties。 For example, if an existing PageContext property contains some other value, ${pagecontext} also returns the PageContext object. 2, note <%@ page iselignored= "True"%> indicates whether the El language is disabled, true to suppress. False indicates that the. JSP2.0 enabled El language is not suppressed. Examples ShowEdit1, for example,<%=request. GetParameter ("username")% > is equivalent to ${param. Username}2, for example, but the following El language can be completed if you get a username empty, then NULL is not displayed, but the value is not displayed. &LT;%=USER.GETADDR ()%> is equivalent to ${user.addr}. 3, for example: <%=request.getattribute ("userlist")%> equivalent to $ {requestscope.userlist}4, for example, the principle is as above example 3. ${requestscope.userlist} 1${sessionscope.userlist} 2${applicationscope.userlist} 3${pageScope.userlist} 4${ UserList} Meaning: The order of execution is 4 1 2 3. “.” The following is just a string, not a real built-in object, not a call to an object. 5. For example, &LT;%=USER.GETADDR ()%> is equivalent to the user in front of the first sentence of ${user.addr}, which is a variable. After the second sentence, the user must be a property in a range.

The definition and use of the El of JSP in Java

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.