1, Jstl dependent El, use Jstl need to import Jstl jar package. Jstl has four main libraries, respectively:
Core: Kernel library, FMT format (date, number), Sql,xml
2, Import jstl Tag library: First need to import the jar package, and then <%taglib prefix= "prefix" uri= "path"%> in the JSP page (eg:1.2 version: <%@ taglib prefix= "C" uri=http:// Java.sun.com/jsp/jstl/core%>)
3. Core Tag library core-> is called C tag (prefix is usually C)
(1) Out and set
<c:out/>: Output
<c:out value= "abc"/> output abc;<c:out value=${num}/> and ${num}
<c:out value=${num} default= "abc"/> Output ABC when ${num} does not exist
<c:out value=${num} default= "abc" escapexml= "false"/> "<", ">" is not converted when EscapeXML is false. Eccapexml default to True
<c:set/>: setting
<c:set var= "num" value= "abc"/> Add a key to PageContext as "ABC" Data in Num,value
<c:set var= "num" VALUE=${ABC} scope= "Session"/> Add the data of key Num,value to ${ABC in session, scope selectable values: Session, page, Request, Application
(2) Remove
<c:remove var= "A" scope= "session"/> Delete domain variable, remove from all domains if no scope is specified
(3) URL
Value: Specifies a path that automatically adds the project name in front of the path
<c:url value= "/index.jsp"/> Actual output is/project name/index.jsp
Sub-label:<c:param> used to add parameters behind the URL
<c:url value= "/index.jsp" >
<c:param name= "username" value= "test"/>
</c:url >
Actual output is/project name/index.jsp?username=%7f7fwwd%9f
var: Specifies the variable name, and once the property is specified, the URL is not output to the page but is saved to the domain variable
Scope: Use with Var
(4) if
If the test property of the If label must be a Boolean value, if the value of test is true, then the contents of the If label are executed, otherwise the
<c:if test= "${not Empty num}" >
<c:out value= "${num}"/>
</c:if>
(Note: no else)
(5) Choose
corresponding switch
<c:choose>
<c:when test= "${num < ten}" > Less than 10</c:when>
<c:when test= "${num > && num <" > greater than 10 less than 20</c:when>
<c:otherwise> Greater than 20</c:otherwise>
</c:choose>
(6) ForEach
Used to loop through arrays, collections, and counting.
Counting method:
I variables from 1 to 100 each plus 2
<c:foreach var= "I" begin= "1" end= "step=" 2 "> (contains 100, equivalent to <=100)
<c:out value= "${i}" >
</c:forEach>
Assigns each element in an array or collection to a variable specified by var
<c:foreach items= "${products}" var= "Product" >
<c:out value= "${product}" >
</c:forEach>
Loop Status:
You can use Varstatus to create a loop state variable
<c:foreach items= "${arr}" var= "E" varstaus= "vs" >
${vs.count} (number of looping elements)
${vs.index} (subscript for the current element)
${vs.first} (whether it is the first element)
${vs.last} (whether it is the last element)
${vs.current} (current Element)
<c:out value= "${e}" >
</c:forEach>
4. FMT Library, Format library
Formatted Date:
<% Date date = new Date (); Pagecontext.setattribute ("date", date); %>
<fmt:formatdate value= "${d}" pattern= "Yyyy-mm-dd HH:mm:ss"/>
Format numbers:
<% request.setattribute ("num", 3.141592653)%>
<fmt:formatnumber value= "${requestscope.num}" pattern= "0.00" > Output Decimal Two bits (4 5 in), 0 (if value=3.1 actually outputs 3.10)
<fmt:formatnumber value= "${requestscope.num}" pattern= "#.##" > Non-complement
Jstl Tag Library