[Jstl] standard Tag Library

Source: Internet
Author: User
Tags tld


1, Jstl Overview before in the "[03-01] JSP custom Label" has been described in the overview of the custom label, and Jstl is a set of tag library, but the manufacturer has already defined a tag library, we no longer need to customize, direct use.
So the use of Jstl is the same as we use custom tags:
    • It also consists of two parts, TLD file and tag processor class
    • Importing a TLD also uses the TAGLIB directive of the JSP

Jstl need to download the jar package separately, after all the others have written it, jstl1.1 often need to Jstl.jar and Standard.jar two jar package (if the import jar package cannot still be used, try to copy the TLD file into the Web-inf directory). Here you can see a total of five TLD files in a common version of Jstl 1.1来 example, as shown below:
    • C.TLD Core Tag Library, most commonly used tags such as loops, branches, expression assignments, etc.
    • FMT.TLD format/internationalization tag library, used to parse data such as date, etc.
    • SQL.TLD database tag library, including access to database tags, etc.
    • X.TLD XML tag library for accessing XML elements
    • The FN.TLD function tag library contains some common functions that can be called directly, such as intercepting strings, etc.

Jstl are often used in conjunction with El expressions, and in Jstl tags, properties are often assigned via El.
2, C.tld part of the label description
    • Expression control Tags: out, set, remove, catch
    • Process Control Tags: if, choose, when, otherwise
    • Loop Label: ForEach, Fortokens
    • URL Action Tags: import, url, redirect
2.1 Expression Control
 
   
  
  1. <c:out value="字符串" />
Output value, which can often be used to replace the tag directly with El.
 
   
  
  1. <c:set var="loggedIn" scope="session" value="${true}" />
The value is stored in the attribute of the name Var in scope range, and the scope default scope is page.
 
   
  
  1. <c:remove var="loggedIn" scope="session" />
The value of Var is removed from the scope range.
 
   
  
  1. <c:catch var="e"><%= 100/0 %></c:catch>
Catch exceptions, exception objects are encapsulated with Var.
2.2 Process Control
 
   
  
  1. <c:if test="${user.login}">Welcome</c:if>
If the value of test is true, the code between <c:if></c:if> runs.
  
 
  1. <c:choose>
  2. <c:when test="${13>4}">
  3. hello!
  4. </c:when>
  5. <c:when test="${4<5}">
  6. hi!
  7. </c:when>
  8. <c:otherwise>
  9. how are u?
  10. </c:otherwise>
  11. </c:choose>
Implement If/else's process logic, note thatmultiple when in choose similar to if else instead of separate if。
2.3 Loop Label
 
   
  
  1. <c:forEach item="${allCustomers}" var="cust">
  2. ${cust}
  3. </c:forEach>
Iterating over the collection allcustomers, each iteration of the element is stored in PageContext, named Cust.
 
   
  
  1. <c:forTokens items="a:b:c:d" delims=":" var="token">
  2. ${token}
  3. </c:forTokens>
The Items property specifies a string that needs to be iterated, delims represents a delimiter, and Var represents a string that is used to split the items produced by the separator.
2.4 URL Action Label
 
   
  
  1. <c:import url="http://www.demo.com/test.txt" />
Used to contain some textual information,<jsp:include> can only contain files from the same web app, while <c:import> can contain resources on other web apps and even on the network.
 
   
  
  1. < span class= "tag" ><C:REDIRECT>
  2. <c:redirect url = "index.jsp" />
  3. <c:param name = "login" value = "true" />
  4. </C:REDIRECT>
For response redirection.
 
   
  
  1. <a href=<c:url value="admin/admin.jsp" />>访问admin.jsp页面</a>
The output URL address, which is overridden by default using URL.

[Jstl] standard Tag Library

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.