1, JSP EL language definition
EL (Expression Language) Objective: To make JSP easier to write.
Expression language inspired by ECMAScript and the XPath expression language, which provides simplified expressions in the JSP in the method. It is a simple language, based on the available namespace (PageContext attributes), nested properties and on the set of operators (arithmetic type, relational and logic-based) access to operator, mapping to the Java class static methods can be spread function and a set of implicit objects.
EL provides a JSP scripting elements to use run-time expressions outside the function. Scripting element refers to the page file can be used to embed Java code in JSP elements. They are often used for objects that affect the operation and implementation of the content generated by the calculation. JSP 2.0 EL expression will be added as a scripting element.
Second, JSP EL Introduction
2,  and. Operator
EL provide "." And "" two operators to access the data.
When you want to access the property name contains special characters, such as. Or? Such as letters or numbers are not symbols, they have to use "." For example:
$ (User.My-Name) should be replaced by $ (user ["My-Name"])
If you want to when the dynamic value, you can use "" to do, and "." Values can not be dynamic. For example:
$ (SessionScope.user [data]) is a variable in the data
3, the variable
EL access the variable data is simple, for example: $ (username). It means that out of a range variable named username.
Because we did not specify which of a range of username, so it will sequence from the Page, Request, Session, Application range search.
If the way to find the username, the direct return, not to look down, but if all of the range are found, would return null.
Properties range in the name of the EL
Second, JSP EL expression in the effective
Effective expression can contain text, operator, variable (object reference) and the function call. We will learn these effective expressions of each:
JSP expression language defines expressions used in the following text:
|Boolean||true and false|
|Integer||And Java like. Can contain any positive or negative, such as 24, -45,567|
|Floating Point||And Java like. Can contain any positive or negative floating point numbers, for example-1.8E-45, 4.567|
|String||Any single or double quotes the string limit. For the single quotes, double quotes and backslashes, use the backslash character as escape sequence. Must be noted that if both ends of the string to use double quotes, you do not need to escape single quotation marks.|
JSP expression language provides the following operators, most of which are commonly used in Java operators:
|Arithmetic||+, - (Binary ),*,/, div,%, mod, - (one dollar)|
|Logical||and, & &, or ,||,!, not|
|Relational||==, Eq,! =, Ne,, gt, <=, le,> =, ge. Compared with other values, or Boolean, string, integer or floating-point type the text for comparison.|
|Air||Empty operator is a prefix operation that can be used to determine the value is empty.|
|Conditional||A? B: C. According to the results of the assignment to assignment A B or C.|
3, implicit object
JSP expression language defines a set of implicit objects, many objects and expressions in the JSP scriplet available:
|pageContext||JSP page context. It can be used to access the JSP implicit objects, such as request, response, session, out, servletContext so. For example, $ (pageContext.response) response object for the page assignment.|
In addition, several implicit objects available, allowing easy access to the following objects:
|param||The request parameter name is mapped to a single string parameter values (by calling ServletRequest.getParameter (String name) get). getParameter (String) method returns the parameters with a specific name. Expression $ (param.name) is equivalent to request.getParameter (name).|
|paramValues||The request parameter name is mapped to a numeric array (by calling ServletRequest.getParameter (String name) get). It is very similar to the param implicit object, but it is to retrieve a string array rather than a single value. Expression $ (paramvalues.name) is equivalent to request.getParamterValues (name).|
|header||Will request the first name of the map to a single String header value (by calling ServletRequest.getHeader (String name) get). Expression $ (header.name) is equivalent to request.getHeader (name).|
|headerValues||Will request the first name of the map to a numeric array (by calling ServletRequest.getHeaders (String) get). It is very similar to the first implicit object. Expression $ (headerValues.name) is equivalent to request.getHeaderValues (name).|
|cookie||Cookie name will be mapped to a single cookie object. Sent to the server, client requests access to one or more cookie. Expression $ (cookie.name.value) return with a specific name of the first cookie value. If the request contains a number of the same name cookie, you should use $ (headerValues.name) expression.|
|initParam||Context initialization parameter name will be mapped to a single value (by calling ServletContext.getInitparameter (String name) get).|
In addition to these two types of implicit objects in addition to the scope of some object allows access to a variety of variables, such as the Web context, session, request, page:
|pageScope||The name of the page scope variable is mapped to its value. For example, EL expression $ (pageScope.objectName) can be used to access a JSP page in the range of objects, you can also use $ (pageScope.objectName.attributeName) to access object properties.|
|requestScope||The scope of the request variable name is mapped to its value. The object allows access to request object. For example, EL expression $ (requestScope.objectName) can be used to access a range of JSP request object, you can also use $ (requestScope.objectName.attributeName) to access object properties.|
|sessionScope|| If the scope of the variable name will be mapped to its value. The object allows access to the session object. For example:
|applicationScope||The application range of the variable name is mapped to its value. Cain-type objects allow access to the application range of the object.|
Third, with particular emphasis on:
1, note that when the expression is referenced by name one of these objects, return the corresponding object rather than the corresponding property. For example: if an existing pageContext attribute containing some other value, $ (pageContext) also return PageContext object.
2, note that <% @ page isELIgnored = "true"%> that are disabled for EL language, TRUE is prohibited. FALSE said they were not prohibited. JSP2.0 EL is enabled in the default language.
4, an example
1, for example,
<% = Request.getParameter ("username")%> is equivalent to $ (param.username)
2, for example, but the following sentence to be completed EL language is empty, if a username is not displayed null, but does not display the value.
<% = User.getAddr ()%> equivalent to $ (user.addr).
3, for example:
<% = Request.getAttribute ("userlist")%> is equivalent to $ (requestScope.userlist)
4, for example, Principle 3 above cases.
$ (SessionScope.userlist) 1
$ (SessionScope.userlist) 2
$ (ApplicationScope.userlist) 3
$ (PageScope.userlist) 4
$ (Uselist) meaning: the implementation of the order of 4123.
"." Back to just a string, no real built-in objects, can not call the object.
4, for example,
<% = User.getAddr ()%> is equivalent to $ (user.addr)
The first sentence of the previous user, as a variable.
The second sentence, user, must be in a certain range of properties.