JSTL + EL ----- java JSP language Elimination)

Source: Internet
Author: User

InIn the popular MVC open mode, JSP is only responsible for Data Rendering. the java code in JSP is a bit "cool" and the code is too messy, the combination of JSTL + EL effectively solves this problem. This article illustrates its role from the perspective of actual practice.

0. EL:In JSP, you can extract objects from the context and output simplified languages. Format: $ {[request/session/applicationScope]. variable name [index]. member variable}, which is valid for [index] of the collection type.

1. JSTLJSPStandardTagLibrary) is a set of standard labels used in JSP to complete page rendering by TAG, that is, coding by webpage.

2. Conditions for using JSTL:

1) jstl-1.x.jar must be introduced in the project (javaEE5 specifications are already supported by default)

2) instructions must be added to jsp <% @ tagliburi = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<% @ Tagliburi = "http://java.sun.com/jsp/jstl/fmt" & nbsp; prefix = "fmt" %> and so on)

3. Although JSTL has many functions, its main purpose is to "render the java objects passed into the three context objects". Therefore, please make a choice when using JSTL.

4. Core labels:

1) condition judgment: <c: iftest = "EL condition"> html Tag, JSTL tag, EL </c: if> the "condition" can be put into any EL that can return the true value (note that there is no else tag, which also reflects the positioning of JSTL-not to process complex services)

2) loop traversal:

<C: forEachvar = "variable" items = "EL set">
Html Tag
Jstl label
EL
</C: forEach>

Var indicates defining a local variable name used inside the loop, and items indicates the set object retrieved from the context object.

5. format tags:

1) format Date: <fmt: formatDatevalue = "EL date type object" pattern = "yyyy-MM-ddhh: mm: ss "/> indicates that a completed date and time can be adjusted as needed or"-"can be replaced)

2) format the number: <fmt: formatNumbervalue = "EL value type object" pattern = "#,###. # "> </fmt: formatNumber> indicates that the number is in the 3,423,456.23 format.

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.