Basic introduction
El expressions are always enclosed in braces and preceded by a dollar ($) prefix: ${expression}.
To access a property in a variable or JavaBean: ${javabean. Property name} or ${javabean["property name"}
[] The operator is more powerful than the DOT function, because by using [] you can access arrays and lists, you can put expressions that contain named variables in brackets, and you can do any level of nesting, as long as you do.
For example, if Musiclist is a ArrayList, you can use ${musiclist[0]} or ${musiclist["0"]} to access the first value of the list. El does not care about the list index without quotes.
If the contents of the brackets are not enclosed in quotation marks, the container is evaluated. If it is indeed enclosed in quotes and is not an array or list index, the container sees it as a direct name for the property or key.
Except for an El implicit object (PageContext), other El implicit objects are maps. From these implicit objects, you can get properties in any 4 scopes, request parameter values, header values, cookie values, and context initialization parameters. An implicit object that is not mapped is PageContext, which is a reference to a PageContext object.
Do not confuse an implicit El Scope object (a property's map) with an object that is bound by a property. In other words, do not confuse the Requestscope implicit object with the specific JSP implicit object request. The access Request object has only one path, which is accessed by PageContext implicit objects (however, something you want to get from the request can be obtained through other El implicit objects, including Param/paramvalues, header/ Headervalues and Cookies).
Basic syntax
I. El Introduction
1. Grammatical structure
${expression}
2.[] and. operator
EL provides. And [] Two operators to access the data.
You must use [] when you want to access a property name that contains special characters, such as. For example:
${user. My-name} should be changed to ${user["My-name"]}
If you want to dynamically take a value, you can do it with [], and. The dynamic value cannot be taken. For example:
${sessionscope.user[data]}, data is a variable
3. Variable
The method of El Access variable data is simple, for example: ${username}. It means to remove a variable whose name is username in a range.
Since we do not specify which range of username, it will be searched sequentially from page, Request, session, application range.
If the way to find username, direct return, no longer continue to find, but if all the scope is not found, it will return null.
Name of attribute range in El
Page Pagescope
Request Requestscope
Session Sessionscope
Application Applicationscope
Second, El implied object
1. Implied objects related to the scope
The El implied object associated with the scope contains the following four: Pagescope, Requestscope, Sessionscope and Applicationscope;
They are basically the same as JSP PageContext, request, session and application;
In El, these four suppressed objects can only be used to obtain the Range property value, i.e. GetAttribute (Stringname), but cannot obtain other relevant information.
For example: We want to get a value that stores a property username in the session, and you can use the following methods:
Session.getattribute ("username") obtains the value of username,
The following methods are used in El
${sessionscope.username}
2. Implied objects associated with the input
There are two hidden objects associated with the input: param and paramvalues, which are the more specific suppressed objects in El.
For example, when we want to take a user's request parameter, we can use the following methods:
Request.getparameter (String name)
Request.getparametervalues (String name)
In El, you can use both Param and paramvalues to get the data.
${param.name}
${paramvalues.name}
3. Other implied objects
Cookies
JSTL does not provide a cookie-setting action,
For example: To obtain a value in the cookie that has a set name of Usercountry, you can use ${cookie.usercountry} to obtain it.
Header and Headervalues
Header stores data that the user's browser and server use to communicate
For example: To get the version of the user's browser, you can use the ${header["User-agent"]}.
In addition, in rare opportunities, it is possible to have different values for the same header name, and you must instead use Headervalues to get the values.
Initparam
Initparam to set the environment parameters for the Web site (context)
Example: General method String UserID = (string) application.getinitparameter ("userid");
You can use ${initparam.userid} to get the name UserID
PageContext
PageContext obtain additional information about the user's requirements or pages.
${pagecontext.request.querystring} Gets the requested parameter string
${pagecontext.request.requesturl} Gets the requested URL, but does not include the requested parameter string
${pagecontext.request.contextpath} The name of the Web application service
${pagecontext.request.method} method to obtain HTTP (GET, POST)
${pagecontext.request.protocol} Obtain the protocol used (http/1.1, http/1.0)
${pagecontext.request.remoteuser} Get user name
${PAGECONTEXT.REQUEST.REMOTEADDR} Gets the user's IP address
${pagecontext.session.new} to determine if the session is new
${pagecontext.session.id} Gets the ID of the session
${pagecontext.servletcontext.serverinfo} to obtain service information on the host side
SAN, El operator
1. Arithmetic operators have five: + 、-、 * or $,/or div,%, or mod
2. There are six relational operators: = = or EQ,!= or NE, < or LT, > or GT, <= or LE, >=, or GE
3. Logical operators have three:&& or and, | | Or OR,!, or not
4. There are three other operators: empty operator, conditional operator, () operator
Example: ${empty param.name}, ${a? B:C}, ${a* (B+c)}