JSP--JSTL (JSP Standard Tag Library)

JSP--JSTL (JSP Standard Tag Library)

Blog description

The information involved in this article comes from Internet collation and personal summary, which means personal learning and experience summary. If there is any infringement, please contact me to delete, thank you!

concept

JavaServer pages tag library JSP standard tag library

Is an open source free jsp tag provided by the Apache organization

effect

Used to simplify and replace java code on jsp pages

install

Rookie tutorial document address https://www.runoob.com/jsp/jsp-jstl.html

Download address

Download the jakarta-taglibs-standard-1.1.2.zip package and extract the two jar files under jakarta-taglibs-standard-1.1.2/lib / standard.jar And jstl.jar Copy the file to / WEB-INF/lib /.

Copy the tld file to be imported under tld to the WEB-INF directory.

Next, we will web.xml Add the following configuration to the file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <jsp-config>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
    <taglib-location>/WEB-INF/fmt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/fmt-rt</taglib-uri>
    <taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/c.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/core-rt</taglib-uri>
    <taglib-location>/WEB-INF/c-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/sql</taglib-uri>
    <taglib-location>/WEB-INF/sql.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/sql-rt</taglib-uri>
    <taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/x</taglib-uri>
    <taglib-location>/WEB-INF/x.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/x-rt</taglib-uri>
    <taglib-location>/WEB-INF/x-rt.tld</taglib-location>
    </taglib>
    </jsp-config>
</web-app>

Use steps

  1. Import jstl related jar package
  2. Import tag library: taglib instruction:

    <%@ taglib %>
  3. Use labels

Common JSTL Tags

If -- if statement equivalent to java code
  1. Properties:

    • test must be attribute, accept boolean expression

      • If the expression is true, the if label body content is displayed; if it is false, the label body content is not displayed
      • In general, the test property value is used in conjunction with the el expression
  2. be careful:

    • c:if tag has no else situation. If you want else situation, you can define a c:if tag
choose -- switch statement equivalent to java code
  1. Using a choose tag declaration is equivalent to a switch declaration

    1. Using the when tag for judgment is equivalent to case
    2. Using the other way tag to make other statements is equivalent to default
foreach -- for statement equivalent to java code

thank

Rookie tutorial

Black horse programmer

Omnipotent network

And the industrious self

Tags: Java JSP xml SQL

Posted on Sun, 28 Jun 2020 02:19:01 -0400 by wing_zero