170819-Knowledge points about Jstl

Source: Internet
Author: User

1.JSTL (JSP standard Tag Library)

[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

Using JSTL requires importing two jar packages 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>    Properties:    value : To output content    default: The default value displayed when the content is empty    escapexml: Whether special characters are automatically escaped, the default is true auto-escaping, and this property is not generally modified     

                                    c:set    function: Set a property in the domain    example: <c:set var= "name" value= "Monkey King" scope= "request" ></c:set>     Properties:    var: Attribute names stored in a domain    value: attribute values stored in a domain    scope: Adding attributes to that field Four optional VALUES (page request session application), default is page   

                                    c: Remove    Action: Remove an attribute from a field    example: <c:remove var= "Name" scope= "Session"/>    properties:     var: The name of the property to remove    scope: The field of the property to remove, four optional VALUES (page request session application)       If this property is not set, the default removal of the specified attribute in four domains.    

                                    c: If    function: Equivalent in Java If statement    example:     <c:if test= "${empty param.name}" >     

                                    C:choose C:when C:otherwise    function: equivalent to If...else    example:     <c:choose>       <c:when test= "${param.score = =" >       

                                    c:foreach    function: You can traverse a collection in a page    example:    <c:foreach items= "${list}" var= "Hero" >      ${hero} <br/>    </c:forEach>         <c:foreach items= "${map}" var= "User" >     ${user.key}---${user.value} <br/>  & Nbsp; </c:foreach>    Properties:    items: The collection to traverse    var: The name of the object reference in the collection            Note: When you traverse a map, you return a set of key-value pairs of structures     We can get through the object. Key gets the key through the object. Value gets        function: Can be used to traverse a set of numbers    example:    <c: ForEach begin= "1" end= "var=" "Index" step= "1" >     <a href=#>${index}</a>   &nBsp; </c:foreach>    Properties:    begin: Starting position, note begin cannot be less than 0    end : End position    var: reference name    step: Step, size per increment    

                                    c:url    Function: 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= "all" >< /c:param>    </c:url>    Properties:    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 to automatically request parameters for the address stitching.      c:redirect    Role: Redirection of Requests    Example:    <c:redirect url= "/ index.jsp ">     <c:param name=" name "value=" Tang priest "></c:param>     </c:redirect>    Properties:    url:      Redirect to Destination address, note that the address does not add the project name by itself.          can add C:param tags to the redirect tag, and can 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 ${CTX} to replace the project name in the page

2. Use <c:url value= "/index.jsp" ></c:url> use URL tag, it will automatically add 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 into the 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/> Determines whether the previous string contains the latter string, is case-insensitive           ${fn:endswith ("Hello", "Alo")}<br/> Determine whether the previous string ends after a string           <!--automatically escapes special characters--    ${fn:escapexml ("

170819-Knowledge points about Jstl

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.