The EL expression of the JSP

Source: Internet
Author: User
Tags tld

Introduction of El Expression

EL full name is Expression Language. El main functions:
1. Access to Data
El expressions are primarily used to replace script expressions in JSP pages to retrieve Java objects from various types of Web domains and get data. (objects in a web domain, accessing JavaBean properties, accessing the list collection, accessing the map collection, accessing an array)
2. Perform operation
The EL expression allows you to perform some basic relational, logical, and arithmetic operations on a JSP page to accomplish some simple logic operations in a JSP page. ${user==null}
3. Get common objects for web development
EL expressions define implicit objects that make it easy for web developers to get a reference to a common Web object to get the data in those objects.
4. Calling the Java method
The EL expression allows the user to develop a custom El function that invokes a method of the Java class through an El expression in a JSP page.

1.1. Access to Data

Get data syntax using el expression: "${identifier}"
The EL expression statement, when executed, invokes the Pagecontext.findattribute method, using the identifier as the keyword, to find the corresponding object from page, request, session, and application four fields, and then returns the corresponding object. Returned "" (Note that it is not NULL, but an empty string).

El expressions can easily get JavaBean properties, or get data from arrays, Collection, and map type collections

1<!--creating objects--2<jsp:usebean id="Stu" class="Jspprojec. Student"Scope="Request"></jsp:useBean>3<!--setting properties, target="${stu}"Be sure to use ${} to get the Stu object, otherwise it's just a string--4<c:Settarget="${stu}"Value="s001"property="Sno"&GT;&LT;/C:Set>5<c:Settarget="${stu}"Value="Zhangsan"property="name"&GT;&LT;/C:Set>6<% Request.setattribute ("Stu", Stu); %>7<c: outValue="${stu.sno}"&GT;&LT;/C: out>
1<% ArrayList list=NewArrayList ();2List.add (0,"Zhangsan");3List.add (1,"Lisi");4List.add (2,"Wangwu");5Request.setattribute ("List", list); To add the list to the request domain, otherwise ${} cannot find6%>7${list[2] }

1.2. Perform operation

Syntax: ${expression},el expression supports the following operators:

1. Relational operators

  

2. Logical operators:

  

  3, empty operator : Checks whether the object is null (NULL)

  4, two-tuple expression : ${user!=null?user.name: ""}
  5, [] and. Number operator

1.4. Invoking the Java method with El

The EL expression syntax allows developers to develop custom functions to invoke methods of the Java class. Syntax: ${prefix:method (params)}
The static method of a Java class can only be called in an El expression, and the static method of the Java class needs to be described in the TLD file before it can be called by an El expression.
The El Custom function is used to extend the functionality of the El expression, allowing the El expression to do what ordinary Java program code can do.

1.5. EL function Development Steps

In general, the development and application of El Custom functions consists of the following three steps:
1. Write a static method of a Java class
2. Write a tag library descriptor (TLD) file that describes the custom function in the TLD file.
3. Import and use custom functions in JSP pages

1.6, the development of El function considerations

After you have written the tag library profile, you need to place it in any subdirectory other than the classes and LIB directories in the <web app >\web-inf directory or Web-inf directory.
The <uri> element in the TLD file uses the URI of the specified TLD file, which in the JSP file needs to be introduced into the tag library description file.
The <function> element is used to describe an El custom function, where:
The <name> child element is used to specify the name of the El Custom function.
The <function-class> child element is used to specify the full Java class name,
The <function-signature> child element is used to specify the signature of a static method in a Java class, and the method signature must indicate the type of the method's return value and the type of each parameter, separating each parameter with a comma.

The EL expression of the JSP

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.