First, El Introduction
1. Grammatical structure
${expression}
2.[] with the. Operator
EL provides. And [] Two operators to access data.
When you want to access a property name that contains some special characters, such as. or? Other than 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 do it with [], and. cannot be dynamically evaluated. For example:
${sessionscope.user[data]} in data is a variable
3. Variables
The EL Access variable data method is 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.
Name of the attribute range in El
Page Pagescope
Request Requestscope
Session Sessionscope
Application Applicationscope
Two, El hidden objects
1. Implied objects related to the scope
The El implied objects associated with the range contain the following four: Pagescope, Requestscope, Sessionscope and Applicationscope;
They are basically the same as JSP PageContext, request, session and application;
In El, these four hidden objects can only be used to obtain the range attribute value, which is getattribute (String name), but cannot obtain other related information.
For example: We want to get the value of storing an attribute username in the session, you can use the following methods:
Session.getattribute ("username") obtains the value of username,
In El, the following methods are used
${sessionscope.username}
2. Implied objects related to the input
There are two hidden objects associated with the input: param and paramvalues, which are the more specific hidden objects in El.
For example, when we want to get the user's request parameters, we can take advantage of 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 hidden Objects
Cookies
JSTL does not provide a cookie-setting action,
Example: To get a value in a cookie that has a setting name of Usercountry, you can use ${cookie.usercountry} to get it.
Headers and Headervalues
The header stores the data that the user's browser and server use to communicate
Example: To get the version of the user's browser, you can use ${header["User-agent"}.
In addition, under rare opportunities, it is possible to have different values for the same header name, and you must instead use Headervalues to obtain these values.
Initparam
Initparam get environment parameters for setting 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 user requirements or pages.
${pagecontext.request.querystring} Gets the requested argument string
${pagecontext.request.requesturl} Gets the requested URL, but does not include the request's argument string
${pagecontext.request.contextpath} The name of the Web application of the service
${pagecontext.request.method} Method of getting HTTP (get, POST)
${pagecontext.request.protocol} Get the protocol used (http/1.1, http/1.0)
${pagecontext.request.remoteuser} Get user name
${PAGECONTEXT.REQUEST.REMOTEADDR} Get the IP address of the user
${pagecontext.session.new} to determine if the session is a new
${pagecontext.session.id} Gets the ID of the session
${pagecontext.servletcontext.serverinfo} access to host-side service information
three, El operator
1. There are five arithmetic operators: + 、-、 * or $,/or div,% or mod
2. There are six relational operators: = = or EQ,! = or NE, < or LT, > or GT, <= or LE, >=, or GE
3. The logical operator has three:&& or an and, | | Or,!, or not
4. There are three other operators: the empty operator, the condition operator, the () operator
The most commonly used expressions:
Empty judgment: ${empty Param.name}
Ternary operation: ${a? B:C}
arithmetic operation: ${a* (B+C)}
Four, El function (functions).
Syntax: Ns:function (arg1, arg2, Arg3 .... ArgN)
Where NS is the predecessor name (prefix), and it must be placed with the predecessor name of the TAGLIB directive
1 El expressions are represented in ${} and can be used in all HTML and JSP tags instead of complex Java code in JSP pages.
2 El expressions manipulate constant variables and implicit objects. The most commonly used implicit objects are ${param} and ${paramvalues}. ${param} represents a value that returns a single string in the request parameter. ${paramvalues} Represents a set of values that return a request parameter. pagescope represents a variable for a page range. Requestscope represents a variable for the Request object. Sessionscope represents a variable in the session scope. Applicationscope represents the variable that is scoped.
3 <%@ page iselignored= "True"%> indicates whether the El language is disabled, and true to suppress. False indicates that the. JSP2.0 enabled El language is not suppressed by default .
4 El Language can display a logical expression such as ${true and false} result is a false relationship expression such as ${5>6} result is false arithmetic expression such as ${5+5} result is ten
5 The variable search scope in El is: page request session application dot operator (.) and "[]" are both representations of the value of the get variable. The difference is [] can show non-speech variables ${uplist[0].lzid = = Zulist.zname? ' Selected ': '}
Transferred from: http://elf8848.iteye.com/blog/888997
JSP el expression (go)