Review and organize 1:jsp standard tag library Jstl

Source: Internet
Author: User

One: What is it:

JSTL is the Apache extension to El expression, Jstl is the tag language! Jstl tag has been very convenient since its use, it is the same as the JSP action tag, but it is not a JSP built-in tag, we need to guide the package, as well as the designated tag library!

Two: Why? What's the effect?

JSP is mainly used to show the data results after the business logic code processing, the inevitable use of loops, Boolean logic, data format conversion and other statements, using JSTL can simplify the code, easy to manage, and jstl customizable labels, more convenient

Three: How to use?

1: Guide Pack

2: Import the tag library in the header of the JSP page.

1 <!--Core Tags -2 <%@ taglib Prefix="C" 3 URI="Http://java.sun.com/jsp/jstl/core" %>4 <!--Formatting Labels -5 <%@ taglib Prefix="FMT" 6 URI="http://java.sun.com/jsp/jstl/fmt" %>7 <!--SQL Tags -8 <%@ taglib Prefix="SQL" 9 URI="Http://java.sun.com/jsp/jstl/sql" %>Ten <!--XML Tags - One <%@ taglib Prefix="x"  A URI="Http://java.sun.com/jsp/jstl/xml" %>
13<!--jstl Function--
14<%@ taglib prefix="FN"

uri="Http://java.sun.com/jsp/jstl/functions" %>

3: Using labels

1 <!--add data with name score value of ${param.score} in PageContext -2 <C:setvar= "Score"value= "${param.score}"/>3 <!--the Choose tag corresponds to the IF/ELSE if/else structure in Java. When the label's test is true, the content of this when is executed. The contents of the otherwise tag are executed when all when label test is false.  -4 <C:choose>5     <C:whenTest= "${score > | | score < 0}">Wrong score: ${score}</C:when>6     <C:whenTest= "${score >=">Class A</C:when>7     <C:whenTest= "${score >=">Class B</C:when>8     <C:whenTest= "${score >=}">Class C</C:when>9     <C:whenTest= "${score >=">Class D</C:when>Ten     <c:otherwise>E-Class</c:otherwise> One </C:choose>

4: Other tags on the internet, many, not to say, should be proficient in the practice

Four: Flexible with---custom labels

1: New label processing class, inherited from Simpletagsupport class override Dotag () method.

1  Public classIftagextendsSimpletagsupport {2          //test is a Boolean type property of the Iftag tag3     Private Booleantest;4         //provide relevant methods5      Public Booleanistest () {6         returntest;7     }8      Public voidSettest (Booleantest) {9          This. Test =test;Ten     } One @Override A      Public voidDotag ()throwsjspexception, IOException { -         if(test) { -              This. Getjspbody (). Invoke (NULL); the         } -     } -}

2: The TLD file is created in the Lib directory of the Web-inf directory of the Web project, which is the declaration file for the tag library and is configured with relevant information.

1 <Tag> 2 <!--Custom Label name -3         <name>If</name> 4 <!--class name -5         <Tag-class>Cn.xxx.IfTag</Tag-class> 6 7         <body-content>Scriptless</body-content>8 9         <attribute>Ten <!--Property name - One             <name>Test</name> A <!--is required - -             <Required>True</Required> - <!--whether the EL expression is supported - the             <Rtexprvalue>True</Rtexprvalue> -         </attribute>  -     </Tag>

3: Referencing a custom label

1 <%2 Pagecontext.setattribute("One", true);3 Pagecontext.setattribute ("both", false);4 %>5 <it:ifTest= "${one}">Xixi</it:if>6 <it:ifTest= "${two}">haha</it:if>7 <it:ifTest= "true">Hehe</it:if>

11

Review and organize 1:jsp standard tag library 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.