Using an El expression in a JSP

Source: Internet
Author: User
Tags ord

    1. El expression: El full name is expression Language, which is to replace the <%=%> script expression.
    2. El main functions:
      • Get 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)

      • Perform the 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}

      • Get Web Development Common objects

      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.

      • 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.

    3. Using El expressions to get data
(1) Use El expression to get data syntax: "${identifier}"    el expression statement when executed, will invoke the Pagecontext.findattribute method, using the identifier as the keyword, from page, request, session, Application

( Note that it is not NULL, but an empty string ). Example: ${user} <%= ((httpservletrequest) pagecontext.getrequest ()). Getcontextpath ()%> Parentheses are required after the object is fetched to continue calling the method on the object ${pagecontext.request.contextpath} This still needs to be remembered for useful
-----------------------------------------------------------Split Line----------------------------------------------------------- --------------------------

(2) El expressions can also easily get JavaBean properties or get data for arrays, Collection, and map type collections, for example:

    1. ${STRS[1]}//Gets the elements in the array

${user.address.city}

${USER.LIST[0]}: Access an ordered collection of elements at a location

${map.key}: Gets the value of the specified key in the Map collection

Iterate through the C tag's foreach in the Jstl tag, which we've already done!

4.el Expression execution operations [focus in focus]

(1) Arithmetic operation: All elements involved in the meta-calculation will be converted to a number, if the error cannot be transferred, empty elements participate in the operation as not involved.
(2) Relational operations: must be remembered

  == --->    eq     for example: 5 = = 5 & #x6216; > 5 ==5 5==5 or {5 eq 5}

! =---> NE

<---> lt

>---> GT

<=---> Le

>=---> GE

(3) Logical operation:

&&---> and for example:{a&&b} or {a&&b} or {A and B}

|| ---> or

! ---> Not

(4) Empty/not empty to determine whether an object or collection or array is null or a length of 0

(5) conditional expression ${user!= null? User.Name: "";

(6) [] and. Number operators

5. use El expressions to get web development common objects

The El expression language defines 11 hidden objects , which make it easy to get some common objects in web development and read the data of those objects.

syntax : ${implicit object name}: Getting a reference to an object

PageContext: Represents PageContext object, note and Pagescope are differentiated

Pagescope: Represents the page field, which can be used to get properties in the page field

Reqeustscope: Represents the Reqeust domain, which can be used to obtain properties in the Reqeust domain

Sessionscope: Represents the Session field, which can be used to get the properties in the Session field

Applicationscope: Represents the application domain, which can be used to obtain properties in the application domain

PARAM: The Map collection representing the request parameters ${param.username} is equivalent to Request.getparameter ("UserName")

Paramvalues: Represents a map collection of requests for a host, but the value of this collection is string[], which is used to obtain a multivalued param equivalent to request.getparametervalues ("UserName")

Header: Gets the Map object for all HTTP request fields

Headervalues: Ibid., gets a map consisting of the request header, but value is a string[]

Note: If there is "-" in the head, example accept-encoding, headervalues["accept-encoding"]

Cookie: Gets the Map object composed of a cookie, the value of this map is a cookie object ${cookie.cookiename.cookievalue}

Initparam: Initialization parameters for the entire Web application configured in the map package, XML

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>

Using an El expression in a 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.