JSP Expression Language (EL)

Source: Internet
Author: User
JSP is used to display dynamic content on a webpage. Generally, java scripts must be embedded in the JSP page to complete complex functions. However, a large number of java scripts make it difficult to maintain JSP pages. A JavaScript-like JSP expression language can be used to generate dynamic content on a webpage and replace JSP script elements (expressions, scripts, and declarations ), el expressions can be used in all HTML and JSP labels.
El expression syntax:
$ {El expression}
$ Indicates the start of the El expression.
El expression specifies the expression.

I. jsp El expressions can be used in the following methods.
1 static text: Contains El expressions, which are calculated during runtime.
Example: ${8 + 5}

2. Standard tag and custom tag attributes: displays dynamic content on the web page.
JSP provides some standard labels, such as <JSP: usebean> and <JSP: Include>. Custom tags are written by the user using the taglib command.
The El expression can be passed as a value to the attribute of the preceding tag. When the expression is calculated at run time, the result value is passed as the property value.
For example:
Pagecontext. setattribute ("color", "# ffccff ");
<Body bgcolor = "$ {pagination. Color}">
7 + 8 =$ {7 + 8}

3. JavaBean and El expressions: You can use el expressions to read the attribute values of JavaBean.
Traditional JSP usually uses the following method to access JavaBean:
<JSP: getproperty name = "mybean" property = "name"/>
<% = Mybean. getname () %>
The El expression is simplified:
$ {Mybean. name}

Ii. enable/disable El expressions
<% @ Page iselignored = "True | false" %>
If this parameter is set to true, El expression is supported.
If this parameter is set to false, El expression calculation is not supported.

Iii. Variables
JSP expression $ {product} calculation result and call pagecontext. like findattribute ("product"), variables in El expressions can reference attributes stored in a standard range (for example, page request session application.

The vertex operators (.) and [] are used to obtain the value of a variable.
For example, A. Identifier-B is equivalent to expr-A [Identifier-B.

Iv. Implicit object
JSP implicit objects are a set of standard classes. The following implicit objects are defined in JSP El:
1 pagecontext: provides access to page attributes. You can access and use the following objects through the pagecontext object.

2 Request: accept the JSP page request from the client. The request information can be accessed using the request object. For example, $ {pagecontext. Request. contextpath} returns the request context path.

3 Param: returns the value that maps the request parameter name to a single string value. For example: $ {Param ["name"]}

4 paramvalues: return a set of values mapped to the client's request parameters.

5 pagination: return the variable names in the page range, which have been mapped to the corresponding values.

6. requestscope: Provides the permission to access the attributes of the request object.

7 sessionscope: return the variable name in the session range.

8 applicationscope: ApplicableProgramVariable name in the specified range.
5. Text Constants
The JSP Expression Language defines the following literal constants:
1 Boolean: true or false.
2 INTEGER: it is the same as the integer in Java.
3. floating point: it is the same as the floating point type in Java.
4 string type: it is caused by single or double quotation marks.
5 NULL: no value. 0 and null strings are not null values.

Vi. Operators
The vertex operators (.) and [] are used to obtain the value of a variable.
! Or the not Boolean value is reversed.
Empty checks for null values
* Multiplication
/Or Div Division
% Or mod evaluate the remainder or modulo
+ Add
<Or lt is less
> Or GT is greater
<= Or Le is less than or equal
> = Or GE is greater than or equal
= Or equal to EQ
! = Or ne is not equal
& Or and logic and
| Or, logical or
Num1? Num2: Result conditional Operator

========================================================== ======================================
[Size = large] El expression dynamic table data plus serial number
<C: foreach Var = "ZB" items = "$ {list}" varstatus = "Index">
$ {Index. Count}
</C: foreach>

========================================================== ======================================
Define page variables and auto-Increment
<C: Set Value = "0" Var = "I" Scope = "page"/> <C: foreach Var = "FB" items = "$ {fb}" varstatus = "Index">
<Tr> <TD width = "10%" align = "center"> <C: If test = "$ {! Empty FB. sfbz} ">
<C: Set Value = "$ {pagination. I + 1}" Var = "I" Scope = "page"/>
<C: Out value = "$ {pagination. I}"/> </C: If>
</TD> <TD width = "40%" type = "codeph" text = "/codeph">
$ {FB. xmmc}
& Lt; TD width = "40%" & gt;
$ {FB. sfbz}
</C: foreach>
========================================================== ======================================
Formatting time
<FMT: formatdate value = "$ {yxqjz}" pattern = "yyyy-mm-dd"/>
<FMT: formatdate value = "$ {zxyprice. startdate2}" type = "date" datestyle = "medium"/>

========================================= =======================================================< br> Cross-row


=============================================== =====================================================< br>

  • Work Plan

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.