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.