[1] Jstl Introduction
> Jstl is the standard tag library for JSPs
> Jstl provides us with some common tags for our daily development use (if, if...else, traversal, date formatting)
> tag Library
-Core: Kernel Tag Library
-One of the most commonly used tag libraries, i.e. we are familiar with C tags.
-fn: function Tag Library
-Function Tag Library it needs to be used in conjunction with El expressions, mainly defining some methods of string manipulation.
-FMT: Formatting tag Library
-Mainly used for date, number formatting and internationalization
-20151019 2015/10/19 10/19/2015
-10000 10,000
-SQL: Database Tag Library
-Used primarily to manipulate databases in JSPs, obsolete
-Xml:xml Tag Library
-Used primarily for parsing XML documents in JSP operations, obsolete
> Use of Jstl
Use Jstl to import two jar packages first
Taglibs-standard-impl-1.2.1.jar
Taglibs-standard-spec-1.2.1.jar
[2] Core Tag Library
-Import Core Tag Library
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
-The core tag library generally uses C as the prefix, so we also call the core tag library the C tag.
-The C tag is the most commonly used tag library in our Jstl, which encapsulates many of the features commonly used in development.
C:out
Function: Enter a content into the page, generally with the EL expression to use!
Example: <c:out value= "" default= "" escapexml= "" ></c:out>
Property:
Value: to output content
Default: Defaults displayed when content is empty
EscapeXML: Whether special characters are automatically escaped, the default value is True auto-escape, the property is not generally modified
C:set
Role: Set a property to a domain
Example: <c:set var= "name" value= "Monkey King" scope= "Request" ></c:set>
Property:
var: Name of the property stored in the domain
Value: The value of the property stored in the domain
Scope: Adds an attribute to that field, four optional values (page request session application), which is the default page
C:remove
Action: Removes an attribute from a field
Example: <c:remove var= "Name" scope= "Session"/>
Property:
var: the name of the property to be removed
Scope: The field of the property to be removed, four optional values (page request session application)
If this property is not set, the default removes the specified attribute from four fields.
C:if
Function: Equivalent to the IF statement in Java
Example:
<c:if test= "${empty param.name}" >
</c:if>
Property:
Test: Receives a Boolean-type value
If the value of test is true then the label body executes
Otherwise, the label body is not executed
C:choose C:when C:otherwise
Function: equivalent to If...else
Example:
<c:choose>
<c:when test= "${param.score = =" >
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
Property:
When the test property in the label:
Receives a Boolean type of value
If the value of test is true then the label body executes
Otherwise, the label body is not executed
Note: Multiple when labels can be specified in the Choose tag, but only one when will be executed.
When all when tags are not executed, the otherwise tag executes.
C:when and c:otherwise cannot be used from C:choose.
C:foreach
Function: The collection can be traversed in the page
Example:
<c:foreach items= "${list}" var= "Hero" >
${hero} <br/>
</c:forEach>
<c:foreach items= "${map}" var= "User" >
${user.key}---${user.value} <br/>
</c:forEach>
Property:
Items: the collection to traverse
var: the name of the object reference in the collection
Note: When traversing a map, a set of key-value pairs is returned
We can get the key through the object. Key to get the value through the object. Value
Function: Can be used to traverse a group of numbers
Example:
<c:foreach begin= "1" end= "var=" "Index" step= "1" >
<a href=#>${index}</a>
</c:forEach>
Property:
Begin: Beginning position, note begin cannot be less than 0
End: The location of the ending
var: the name of the reference
Step: Step size, each self-increment
C:url
Role: Can create a complete absolute path
Example:
<c:url value= "/index.jsp" >
<c:param name= "name" value= "Monkey King" ></c:param>
<c:param name= "Age" value= "></c:param>"
</c:url>
Property:
Value: The address to be set, note that the address should start with/or not add the project name
You can add the C:param tag to the URL tag, and you can automatically request parameters for the address stitching.
C:redirect
Role: redirect of the request
Example:
<c:redirect url= "/index.jsp" >
<c:param name= "name" value= "Tang priest" ></c:param>
</c:redirect>
Property:
Url:
Redirect to the destination address, and note that the address does not add the project name on its own.
The C:param tag can be added to the redirect tag to automatically request parameters for the address stitching.
Note: The redirect tag automatically sets the project name for us and does not need to be set manually!
Three ways to set an absolute path:
1.<c:set var= "CTX" value= "${pagecontext.request.contextpath}" ></c:set>
In this way, you can use the ${ctx} to replace the project name in the page
2. Use <c:url value= "/index.jsp" ></c:url>
Using the URL tag, it automatically adds the project name to the absolute path
3.<base href= "Http://${pagecontext.request.servername}:${pagecontext.request.serverport}${ PageContext.request.contextPath}/"/>
Use the base tag to make all relative paths in the page, plus the project name
[3] Function Tag Library
Role: the function tag library needs to be used in conjunction with the El expression, the method inside it is the operation of some strings
Introducing function Tag Library: <%@ taglib prefix= "FN" uri= "Http://java.sun.com/jsp/jstl/functions"%>
Example:
${fn:contains ("Hello", "He")} <br/> Determine if the previous string contains the last string
${fn:containsignorecase ("Hello", "He")} <br/> Determine if the previous string contains the latter string, not case-sensitive
${fn:endswith ("Hello", "Alo")}<br/> Determines whether a string before the end of a string
<!--automatically escapes special characters--
${fn:escapexml ("
<!--Fn:join is used to convert a string array to a character, and the second parameter represents the connector--
${fn:join (STRs, ",")}<br/> A string array to specify string concatenation as a new string
${fn:split ("A,b,c,d,e", ",") [2]}<br/> A string that is split into a character array with the specified character
${fn:trim ("ABCD")}<br/> Remove the front and back spaces of the string
The rest of the methods refer to alt+/
JSP Standards Tag Library (JSTL) (JSP standard tag libraries)