About Jstl and El

Source: Internet
Author: User

EL

Expression Language, expressions language, through the operation exists in the PageContext and so on data, the implementation of JSP to write more simple, simply use El without introducing jar package, as long as the container support.

The hidden object of El

El Basic use

${LD} is equivalent to looking for the LD variable sequentially from Pagescope-requestscope-sessionscope-applicationscope, returning its value if there is one, without returning NULL if the variable position is determined, and can be obtained directly, For example, ${requestscope.ld}. In addition to the implied objects mentioned above, El considers all other content as a variable in a domain.

El syntax

In addition, El can also perform common operations

    • Arithmetic operators + 、-、 *,/(or DIV) and% (or mod)
    • relational operators = = (or eq),! = (or NE), < (or LT), > (or GT), <= (or Le), and >= (or GE)
    • logical operators && (OR and), | | (OR) and! (or not)
    • Validation operator Empty
El Get attribute parsing

Assuming that you have already added the user object to Requestscope, now you want to get the Name property of the User object: Use ${user.name} to get the Name property of the user object, the way to obtain the property is not through the variable that is defined private String Username, instead of removing get and lowercase for name based on Method GetName (), modify the username to username1 use of ${user.name} without effect.

El Get Complex properties

Use El to get the Name property of the group property of the User object, you can use ${user.group.name}, get the array with El the second parameter can be ${array[1]}, get K1 in the map can be obtained for ${MAP.K1}.

The JSTL is usually used in conjunction with El.

Jstl

JSP standard tag library,jsp, is a continuous improvement of the open source JSP tag library, its use requires container support, can be elegant label alternative to the Java code in JSP. Jstl can provide more controllable details than El.

Configure Usage Configuration

Use Jstl to introduce Jstl.jar and Standard.jar two packages, add tags to jsp files

    1. <%@ taglib uri="Http://java.sun.com/jsp/jstl/core" prefix="C"%>
Core

The core library provides common tags for out, set, remove, and foreach, using examples:

  1. <c:choose >
  2. <c:when test="${v1 GT v2}" >
  3. V1 Greater than V2
  4. </c:when>
  5. <c:otherwise>
  6. V1 Greater than V2
  7. </c:otherwise>
  8. </c:choose>
Format

The format library provides control labels for formatting, such as:

  1. Today (default):<fmt:formatdate value="${today}"/><br/>
  2. Today (default):<fmt:formatdate value="${today}" type="date"/>< br/>
  3. Today (default):<fmt:formatdate value="${today}" type="Time"/><BR />
  4. Today (default):<fmt:formatdate value="${today}" type="both"/>< br/>
  5. Today (default):<fmt:formatdate value="${today}" type="Both" datestyle="full" /><br/>
  6. Today (default):<fmt:formatdate value="${today}" pattern="Yyyy/mm/dd HH:mm:ss" /><br/>

Can get:

Summarize

In general, through Jstl and El, can reduce the JSP page programming work, in the way of labeling optimization, through the function of Jstl and El Display, make JSP responsibility more single, development division more clear.

About Jstl and El

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.