JSP--EL expression

Posted Jun 28, 20202 min read

JSP--EL expression

Blog description

The information involved in the article comes from the Internet collation and personal summary, which means personal learning and experience summary. If there is any infringement, please contact me to delete, thank you!

Concept

Expression Language

JSP Expression Language(EL) makes accessing data stored in JavaBeans very simple. JSP EL can be used to create both arithmetic expressions and logical expressions. Integers, floats, strings, constants true, false, and null can be used in JSP EL expressions

Role

Replace and simplify the writing of java code in jsp pages

Syntax

${Expression}

Note

  • jsp supports el expressions by default. If you want to ignore the el expression

    Set the page instruction in jsp

      isELIgnored="true" ignores all el expressions in the current jsp page
  • Ignore the current el expression

      \${Expression}

Use

Operation
  • Operator:

    1. Arithmetic operator:+-* /(div)%(mod)

    2. Comparison operator:> <>= <= == !=

    3. Logical operators:&&(and) ||(or) !(not)

    4. Empty operator:empty

      • Function:Used to determine whether a string, collection, array object is null or the length is 0
      • ${empty list}:Determine whether the string, collection, array object is null or the length is 0
      • ${not empty str}:indicates whether the string, collection, or array object is not null and the length is >0
Get value
  1. El expressions can only get values ​​from domain objects

  2. Grammar:

    1. ${domain name. key name}:Get the value of the specified key from the specified field

      • Domain name:

        1. pageScope --> pageContext
        2. requestScope --> request
        3. sessionScope --> session
        4. applicationScope --> application(ServletContext)
      • Example:stored name=张三 in the request field

      • Get:${requestScope.name}

    2. ${key name}:It means to search for the value corresponding to the key from the smallest field in turn until it is found.

    3. Get the values ​​of objects, List collection, Map collection

      1. Object:${domain name. key name. attribute name}

        • Essentially call the getter method of the object
      2. List collection:${domain name. key name[index]}

      3. Map collection:

        • ${domain name. key name. key name}
        • ${domain name. key name["key name"]}

thank

Dark Horse Programmer

Universal Network

And hardworking self