当前位置:网站首页>Le byte explains JSP and JSTL

Le byte explains JSP and JSTL

2020-12-09 15:04:29 Ah, floating


JSP and JSTL

primary coverage

JSP

JSP Basic grammar of

brief introduction

​ JSP:Java Server Page SUN Dynamic web programming technology provided by the company , yes Java Web Dynamic resources on the server side .

​ It compared html for ,html Only static data can be provided to users , and Jsp Technology allows you to nest java Code , Provide users with dynamic data .

​ comparison servlet for ,servlet It's hard to typeset the data , and jsp Except that it can be used java Code generates dynamic data at the same time , It's also easy to typeset the data .

​ Whether it's JSP still Servlet, Although both can be used to develop dynamic web resources . But because of this 2 Gate technology has its own characteristics , In long-term software practice , People gradually put servlet As web Controller components in the application to use , But the JSP Technology is used as a data display template .

​ Actually Jsp It's just one. Servlet, When we first visited Jsp When ,Jsp The engine will take this Jsp translate Become a Servlet, This document is stored in tomcat( Source directory ) Medium work Directory

preparation
To configure IDEA

​ This step is not necessary , Of course, because Some default configuration items in the editor are not perfect , such as " Coding format "、 Page templates, etc . We can build JSP Before the page is modified to what we need .

1. choice "File" —> "Settings..."

2. Set the encoding format . Search for "encode", choice "File Encoding"

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-aWGzNmLu-1607481120171)(/jsp_idea To configure jsp_3.png)]

3. Set the page template . Search for "template", choice "File and Code Templates", Choose... On the right "Other", Choose the one below "Jsp File"

newly build JSP page
notes

​ stay JSP Two kinds of annotation syntax operations are supported in :

​ One is to display comments , This annotation is allowed to be seen by the client ; The other is implicit annotation , Such comments are not visible to the client

​ ① Show annotation Syntax : from HTML Style inherited from

​ ② Implicit annotation Syntax : from JAVA Style inheritance ;JSP My own notes

​ JSP Three ways to annotate :

1) //  notes , Single-line comments   /*  Multiline comment */ 

2)<!--  HTML Style notes  -->

3)<%--   JSP notes   --%>
Scriptlet

​ stay JSP The most important part of it is Scriptlet( Script applet ), All embedded in HTML In code Java Program .

​ stay JSP There are three of them Scriptlet Code : All must use Scriptlet Mark out

 The first one is :<%    %>: java  Script segment , You can define local variables 、 Write sentences 

 The second kind :<%!   %>: Statement , You can define the global ( member ) Variable 、 Method 、 class 

 The third kind of :<%=  %>: expression , A variable or concrete content 

​ Through observation, it can be concluded that java Of documents jsp Code understands three kinds of small scripts

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE >
<html>
    <head>
           <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Scriptlet</title>
    </head>
    <body>
        <%
            String str = "Hello JSP";
            System.out.println(str);
            response.getWriter().write(str);
        %>
        <%!
            String memberStr = "a member String";
        %>
        <%=memberStr%>
        <h1>This is a JSP page!!</h1>
    </body>
</html>

JSP The command tag of

​ Use include operation , Some repetitive code can be included to continue to use , From the normal composition of the page , Sometimes it can be divided into several areas . And some of these areas may never need to change , One of the specific content areas changed . Now there are two ways to do this .

​ Method 1 : At every JSP page (HTML) Both contain toolbars 、 Header information 、 Tail information 、 The specific content

​ Method 2 : Put the toolbar 、 Header information 、 The tail information is divided into separate files , Import directly when using

​ Obviously , The second method is better than the first one , The first is a lot of duplicate code , And it's very inconvenient to modify , stay JSP If you want to implement the operations contained in , There are two ways : Static inclusion Dynamic inclusion , Static inclusion uses include Command can , Dynamic inclusion requires the use of include Action tag .

include Static inclusion
<%@ include file=" File path to include " %>  <!--  Relative paths  -->

for example :

<%@include file="include.jsp" %>
 or 
<%@include file="include.html" %>

​ Static inclusion is to replace the content directly , It's like a variable defined in a program , Is in servlet Engine translation , Just include the contents of this document ( The source code of the two files is integrated together , All in _jspService In the method ), So there's only one servlet, So two pages can't have the same name variable . A little bit more efficient . High coupling , inflexible .

include Dynamic inclusion

​ Dynamic inclusion in the compilation phase of the code , The contained and included parts are two separate parts , Only when running , Only when dynamic is included , It's like calling a method .

<jsp:include page="include.jsp"></jsp:include>

Be careful : Dynamic inclusion , in Don't add anything , Including Spaces , Unless you confirm that you want to use parameters , Otherwise, the report will be wrong !

<jsp:include page="include.html"></jsp:include>
<%
    String a = "hello.jsp";
%>
<jsp:include page="<%=a %>"></jsp:include>

​ Using dynamic inclusion, you can also pass parameters between pages .

​ The receiving parameters are passed through request.getParameter(name);

<jsp:include page="hello.jsp" flush="true">
    <jsp:param name="uname" value="zhangsan"/>
</jsp:include>

​ hello.jsp

<!--  Receiving parameters  -->
<%=request.getParameter("uname")%>

 Insert picture description here

JSP Four domain objects of

Four attribute ranges

​ stay JSP The scope of saving four properties is provided in , The so-called property preservation range , It refers to a set object , How many pages can you save and continue to use

  1. page Range

    ​ pageContext : Save properties in only one page , No effect after jump

  2. request Range

    ​ request : Save in one request only , After the server jumps, it still works

  3. session Range

    ​ session : In the context of a conversation , Any jump can be used

  4. application Range

    ​ application : Save... On the entire server

Method type describe
public void setAttribute(String name, Object o) Ordinary Set the name and content of the property
public Object getAttribute(String name) Ordinary Take the attribute according to the attribute name
public void removeAttribute(String name) Ordinary Delete the specified property
The scope of attribute validation
  1. page

​ This page gets , Server side jump (<jsp :forward>) Invalid after

  1. request

    Server jump is valid , Invalid client jump

    If it's a client jump , It's equivalent to two requests , Then the first request will not exist ; If you want the client or server to jump , If they can be preserved , We need to continue to expand the scope .

  2. session

    Both the client and the server can obtain , But now restart a new browser , You cannot get the previously set session 了 , Because every one of them session Save only in the current browser , And get it on the relevant page .

    For the server , Every client connected to it is a session

    If you want to set the property once , Whether it's a new browser or not, you can get it and use it application

  3. application

    be-all application Properties are stored directly on the server , All users ( every last session) Can be accessed directly

    As long as it's through application Set properties , Then all of them session All can be obtained , It means public content , But if the server restarts at this point , You can't get , Because after shutting down the server , All attributes are gone , So you need to reset .

ask : Which range to use ?

​ answer :<font color="red"> As small as reasonably possible </font>

EL Use of expressions

EL The syntax of the expression

​ EL(Expression Language) It's to make JSP It's easier to write . The inspiration of expression language comes from ECMAScript and XPath Expression language , It is provided in JSP The method of simplifying expression in , Give Way Jsp The code is much simpler .

 The grammatical structure is very simple : ${expression}

​ EL Expressions generally operate on <font color="red"> Data in domain objects </font>, You can't manipulate local variables .

​ The concept of domain objects is in JSP Four of them :pageContext, request, session, application; The range is in turn , This page , One request , One session , The whole application .

​ When you need to specify to find data from a specific domain object, you can use the spatial objects corresponding to the four domain objects , Namely :pageScope, requestScope, sessionScope, applicationScope.

​ and EL The default search method is from small to large , Just find it . When all domain objects are found but not found, an empty string is returned "".

EL Use of expressions
get data

Set the data in the domain object

<%
    pageContext.setAttribute("uname","zhangsan"); // page Scope 
    request.setAttribute("uname","lisi"); // request Scope 
    session.setAttribute("uname","wangwu"); // session Scope 
    application.setAttribute("uname","zaholiu"); // application
%>

Get the value of the domain object

<%--  Get the data in the domain object : The default search method is from small to large , Find and stop . If none of the four ranges is found , Returns an empty string .--%>
${uname} <!--  The output is :zhangsan -->

Gets the value of the specified domain object

${pageScope.uname}             <!-- page Scope  -->
${requestScope.uname}         <!-- request Scope  -->
${sessionScope.uname}         <!-- session Scope  -->
${applicationScope.uname}     <!-- application Scope  -->

obtain List

<%
    List<String> list = new ArrayList<String>();
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");
    request.setAttribute("list", list);
%>
<%--
     obtain List The data with the subscript specified in 
        ${list[ Subscript ] }
     Get the length of the collection 
        ${list.size()}
     notes :
       list Represents the variable name in the domain object ( Restricted variable name )
--%>
${list[1] }  

obtain Map

<%
    Map map = new HashMap();
    map.put("aaa", "111");
    map.put("bbb", 2222);
    map.put("ccc-a", 333);
    request.setAttribute("map", map);
%>
<%--
     obtain Map The value specified in the 
       ${map["key"] }  or  ${map.key }
     notes :
        map Represents the variable name in the domain object ( Restricted variable name )
--%>
${map.aaa }
${map["bbb"]}

obtain JavaBean object

User.java

public class User {

    private Integer userId;
    private String uname;
    private String upwd;

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUname() {
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public String getUpwd() {
        return upwd;
    }

    public void setUpwd(String upwd) {
        this.upwd = upwd;
    }
}
<%
    User user = new User();
    user.setUserId(1);
    user.setUname("zhangsan");
    user.setUpwd("123456");
    request.setAttribute("user",user);
%>
<%-- JavBean The property fields in the need to provide get Method  --%>
${user} <%--  Get objects  --%>
${user.uname} <%-- Get the properties in the object --%>
empty
<%--
    empty
         Determine whether the domain object is empty . It's empty , return true; Not empty return false;
            ${empty  Restricted variable name  }
         Judge whether the object is not empty .
            ${!empty  Restricted variable name  }
--%>
${empty uname}
${empty list}
${empty map}
${empty user}
EL operation
<%
    request.setAttribute("a", 10);
    request.setAttribute("b", 2);
    request.setAttribute("c", "aa");
    request.setAttribute("d", "bb");
%>

Equivalent judgment

<%--
     Compare two values for equality , return true or false
        ==   or   eq
--%>
${a == b }
${c == d }
${c eq d }
${a == 5 }
${c == 'aa' }

Arithmetic operations

<%--
     Add : +
     Subtraction : -
     Multiplication : *
     division :    /  or  div
--%>
${a + b }
${a / b }  or  ${a div b }

Size comparison

<%--
     Greater than :>
     Less than :<
     Greater than or equal to :>=
     Less than or equal to :<=
--%>
${a > b}
${a + 1 > 10 }
${a + b >= 10 }
${a > b && b > 5 }
${a + b > 10 || a - b > 5 }

JSTL

Use of labels

​ Java Server Pages Standard Tag Libray(JSTL):JSP Standard label library , Is a collection of custom tag class libraries , Used to solve some common problems , For example, iterate over a map or set 、 Conditions for testing 、XML Handle , Even database and access to database operations and so on .

​ We're just going to talk about JSTL The most important label in , Iterate over the collection and format the number and date tags .

Core tag library

http://java.sun.com/jsp/jstl/...

​ contain Web Common work of application , such as : loop 、 Expression assignment 、 Basic input and output, etc .

Format tag library

http://java.sun.com/jsp/jstl/fmt

​ The work of formatting and displaying data , such as : Format the date in different areas .

​ In order to be in JSP Page using JSTL Class library , You must use the following format taglib Instructions :

<%@taglib uri="" prefix="" %>

​ for example :

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

​ The prefix can be anything , Following specifications can make code written by different people in a team more similar ; therefore , It is recommended to use prefixes designed in advance .

​ At this point, you need to import two jar package

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-O1CY3wpj-1607481120180)(/jstl_1.png)]

​ from Apache Standard tag library for downloading binary packages (jakarta-taglibs-standard-current.zip).

​ Official download address :http://archive.apache.org/dis...

​ download jakarta-taglibs-standard-1.1.2.zip Pack and unzip , take jakarta-taglibs-standard-1.1.2/lib/ Of the two jar file :standard.jar and jstl.jar Copy the file to the specified directory of the project .

Conditional action tag

​ Conditional action instructions are used to handle situations where the output of a page depends on certain input values , stay Java It's using if、 if…else and switch Statement to process . stay JSTL There are also 4 Tags can execute conditional action commands :if、 choose、when and otherwise.

if label

​ if The tag tests a condition first , If the result of the conditional operation is true, It deals with its main content , Test results are stored in a Boolean In the object , And create a bounded variable to refer to Boolean object . You can use var Property to set the restricted variable name , utilize scope Property to specify its scope of action .

Grammar format
<c:if test="<boolean>" var="<string>" scope="<string>">
   ...
</c:if>
attribute

if Tags have the following properties :

attribute describe Is it necessary? The default value is
test Conditions yes nothing
var Variables used to store conditional results ( Restricted variable name ) no nothing
scope var The scope of the property
Value for :page\
request\ session\ application no page
Example
<%
    request.setAttribute("flag",true);
    request.setAttribute("num",1);
%>
<c:if test="${flag}">
   <p> The result is true<p>
</c:if>
<c:if test="${num > 0}">
   <p>num Value ratio of 0 Big <p>
</c:if>

notes :<font color="red"> JSTL There is no else label </font>, To simulate else Scenario , You need to use two if label , And these two labels are contrary Conditions .

choose、when and otherwise label

​ choose and when The role of labels is related to Java Medium switch and case The key words are similar , Used to make a choice among many options . in other words : They provide content for mutually exclusive conditional execution .

​ switch There are case, and choose The label corresponds to when,switch There are default, and choose There are tags in the tag. otherwise.

Grammar format
<c:choose>
    <c:when test="<boolean>">
        ...
    </c:when>
    <c:when test="<boolean>">
        ...
    </c:when>
    ...
    ...
    <c:otherwise>
        ...
    </c:otherwise>
</c:choose>
attribute
  • choose Tags have no properties .
  • when There is only one label test attribute .
  • otherwise Tags have no properties .
Example
<%
    request.setAttribute("score", 90);
%>
<c:choose>
    <c:when test="${score < 60 }">
        <h3> You little scum !</h3>
    </c:when>
    <c:when test="${score >= 60 && score < 80 }">
        <h3> The revolution has not yet succeeded , Comrades still need to work hard !</h3>

    </c:when>
    <c:otherwise>
        <h3> You are wonderful !</h3>
    </c:otherwise>
</c:choose> 
Be careful
  • choose Labels and otherwise Tags have no properties , and when The label must be set test attribute
  • choose There must be at least one when label , There can be no otherwise label
  • otherwise The label must be placed on the last when After tag
  • choose There can only be... In the label when Labels and otherwise label ,when Labels and otherwise Tags can nest other tags
  • otherwise The label is at all when Only when the tag is not executed

Iteration tags

​ forEach It is to iterate the main content several times , Or iterate over a collection of objects . Objects that can be iterated include all java.util.Collection and java.util.Map Interface implementation , And an array of objects or primitive types . He can To iterate java.util.Iterator and java.util.Enumeration, But it can't be used in more than one action command Iterator perhaps Enumeration, because Iterator perhaps Enumeration Can't reset (reset). The meaning of each attribute is as follows :

forEach label
Grammar format
<c:forEach
    items="<object>"
    begin="<int>"
    end="<int>"
    step="<int>"
    var="<string>"
    varStatus="<string>">
</c:forEach>    
attribute
attribute describe Is it necessary? The default value is
items Data to be cycled no nothing
begin The starting element (0= First element ,1= The second element ) no 0
end The last element (0= First element ,1= The second element ) no Last element
step Step length of each iteration no 1
var Represents the variable name of the current entry no nothing
varStatus The name of the variable that represents the state of the loop no nothing

forEach varStatus attribute

  • index: The current iteration starts from 0 The initial iteration index
  • count: The current iteration starts from 1 The number of iterations started
  • first: It is used to indicate whether the current iteration is the first iteration
  • last: A flag used to indicate whether the current iteration is the last iteration
Example

1. Traverse the main content many times

<c:forEach begin=" Starting number " end=" End number " step=" Iterated algebra " var=" Restricted variable name ">

</c:forEach>

 amount to java Of for loop :

for(int i = 0; i < 10; i++) {

}

as follows :

<!--  Traverse the main content many times   -->
<c:forEach begin="0" end="10" var="i" >
     title ${i }<br>
</c:forEach>

2. loop

<c:forEach items=" The set of loops " var=" Restricted variable name " varStatus=" Information about the current member object ">
                    
</c:forEach>

 amount to java Of foreach loop :

for(String str : list) {

}

as follows :

 <%
    List<String> list = new ArrayList<String>();
    for (int i = 1; i <= 10; i++) {
        list.add("A:" + i);
    }
    pageContext.setAttribute("li", list);
%>
     
<!--  Cycle set  -->
<c:forEach items="${li }" var="item">
    ${item }
</c:forEach>
<hr>
<table align="center" width="800" border="1" style="border-collapse: collapse;">
    <tr>
        <th> name </th>
        <th> Current member subscript </th>
        <th> Number of current member cycles </th>
        <th> Whether it's the first time it's cycled </th>
        <th> Whether it's the last time it's cycled </th>
    </tr>
    <c:forEach items="${li }" var="item" varStatus="itemp">
        <tr>
            <td>${item }</td>
            <td>${itemp.index }</td>
            <td>${itemp.count }</td>
            <td>${itemp.first }</td>
            <td>${itemp.last }</td>
        </tr>
    </c:forEach>
</table>

<!--  Loop object collection  -->
<%
    List<User> userList = new ArrayList<User>();
    User user = new User(1,"zhangsan","123456");
    User user2 = new User(2,"lisi","123321");
    User user3 = new User(3,"wangwu","654321");
    userList.add(user);
    userList.add(user2);
    userList.add(user3);
    //  Set data into scope 
    request.setAttribute("userList", userList);
%>
<c:if test="${!empty userList }">
    <table align="center" width="800" border="1" style="border-collapse: collapse;">
        <tr>
            <th> The user id </th>
            <th> User name </th>
            <th> User password </th>
            <th> The user action </th>
        </tr>
        <c:forEach items="${userList }" var="user">
            <tr align="center">
                <td>${user.userId }</td>
                <td>${user.uname }</td>
                <td>${user.upwd }</td>
                <td>
                    <button> modify </button> 
                    <button> Delete </button>
                </td>
            </tr>
        </c:forEach>
    </table>
</c:if>

<!--  Traverse Map -->
<%
    Map<String,Object> map = new HashMap<String,Object>();
    map.put("map1", "aaa");
    map.put("map2", "bbb");
    map.put("map3", "ccc");
    pageContext.setAttribute("map", map);
%>
<c:forEach items="${map }" var="mymap">
     key :${mymap.key }- value :${mymap.value } <br>
</c:forEach>

Format action tags

​ JSTL Provides tags for formatting and parsing numbers and dates , There is something in our discussion :formatNumber、formatDate、parseNumber And parseDate.

formatNumber label

​ formatNumber Tags are used to format numbers , percentage , currency . The tag formats numbers in the specified format or precision .( Converts numeric data to a string type of a specified format .)

Grammar format
<fmt:formatNumber
  value="<string>"
  type="<string>"
  var="<string>"
  scope="<string>"/>
attribute
attribute describe Is it necessary? The default value is
value Number to display yes nothing
type NUMBER,CURRENCY, or PERCENT type no Number
var Variables that store formatted numbers no Print to page
scope var The scope of the property no page

Be careful :

  1. If set var attribute , The formatted result will not be output , Need to pass through el Expression acquisition var The corresponding restricted variable name
  2. The default type (type) The values for number. Value for :number Numerical type 、percent Percentage type 、currency Currency type
Example
<fmt:formatNumber value="10" type="number" var="num" /> ${num } <br>
<fmt:formatNumber value="10" type="percent"  />  <br>
<fmt:formatNumber value="10" type="currency"  />  <br>
<!--  Set time zone   -->
<fmt:setLocale value="en_US"/>
<fmt:formatNumber value="10" type="currency"  />  <br>
formatDate label

​ formatDate Tags are used to format dates in different ways .( take Date Type data to a string type of the specified format .)

Grammar format
<fmt:formatDate
  value="<string>"
  type="<string>"
  dateStyle="<string>"
  timeStyle="<string>"
  pattern="<string>"
  timeZone="<string>"
  var="<string>"
  scope="<string>"/>
attribute
attribute describe Is it necessary? The default value is
value Date to display yes nothing
type DATE, TIME, or BOTH no date
dateStyle FULL, LONG, MEDIUM, SHORT, or DEFAULT no default
timeStyle FULL, LONG, MEDIUM, SHORT, or DEFAULT no default
pattern Custom format mode no nothing
timeZone Time zone showing date no Default time zone
var The name of the variable that stores the formatted date no Show on page
scope Store the range of formatted log variables no page

Tag format mode

Code describe example
y Years without era . If the year excluding the era is less than 10, The year without leading zero is displayed . 2002
M Month numbers . There is no leading zero for a single digit month . April & 04
d One day of the month . There is no leading zero for a single digit date . 20
h 12 An hour system . There is no leading zero for one digit hours . 12
H 24 An hour system . There is no leading zero for one digit hours . 0
m minute . There is no leading zero for one digit minutes . 45
s second . The number of seconds in a single digit has no leading zero . 52
Example
<%
    request.setAttribute("myDate", new Date());
%>
     
${myDate } <br/>
<fmt:formatDate value="${myDate }" /><br/>
<fmt:formatDate value="${myDate }" type="date"/><br/>
<fmt:formatDate value="${myDate }" type="time"/><br/>
<fmt:formatDate value="${myDate }" type="both"/><br/>
<fmt:formatDate value="${myDate }" type="both" dateStyle="full"/><br/>
<fmt:formatDate value="${myDate }" type="both" dateStyle="long"/><br/>
<fmt:formatDate value="${myDate }" type="both" dateStyle="short"/><br/>
<fmt:formatDate value="${myDate }" type="both" timeStyle="full"/><br/>
<fmt:formatDate value="${myDate }" type="both" timeStyle="long"/><br/>     
<fmt:formatDate value="${myDate }" pattern="HH:mm yyyy/MM/dd"/><br/>
parseNumber label

​ parseNumber Tags are used to parse numbers , percentage , currency .(parseNumber Tags can put numbers 、 Convert a string of currency or percentage type to numeric type .)

Grammar format
<fmt:parseNumber
  value="<string>"
  type="<string>"
  var="<string>"
  scope="<string>"/>
attribute
attribute describe Is it necessary? The default value is
value The number to parse no Body
type NUMBER,,CURRENCY, or PERCENT no number
var The variable that stores the number to be parsed no Print to page
scope var The scope of the property no page
Example
<fmt:parseNumber value="100"  /> <br>
<fmt:parseNumber value="100"  type="number" /> <br>
<fmt:parseNumber value="100%"  type="percent" /> <br>
<fmt:parseNumber value="¥10.00"  type="currency" /> <br>
parseDate label

​ parseDate Tags are used to parse dates .( Converts a string of specified format to Date type .)

Grammar format
<fmt:parseDate
   value="<string>"
   type="<string>"
   dateStyle="<string>"
   timeStyle="<string>"
   pattern="<string>"
   var="<string>"
   scope="<string>"/>
attribute
attribute describe Is it necessary? The default value is
value Date to display yes nothing
type DATE, TIME, or BOTH no date
dateStyle FULL, LONG, MEDIUM, SHORT, or DEFAULT no default
timeStyle FULL, LONG, MEDIUM, SHORT, or DEFAULT no default
pattern Custom format mode no nothing
var The name of the variable that stores the formatted date no Show on page
scope Store the range of formatted log variables no page
Example
<fmt:parseDate value="2020-01-06" type="date" /> <br>
<fmt:parseDate value="2020/01/06" pattern="yyyy/MM/dd" /> <br>

e
value="<string>"
type="<string>"
dateStyle="<string>"
timeStyle="<string>"
pattern="<string>"
var="<string>"
scope="<string>"/>


#####  attribute 

|  attribute       |  describe                                   |  Is it necessary?  |  The default value is      |
| --------- | ------------------------------------- | -------- | ---------- |
| value     |  Date to display                           |  yes        |  nothing          |
| type      | DATE, TIME,  or  BOTH                   |  no        | date       |
| dateStyle | FULL, LONG, MEDIUM, SHORT,  or  DEFAULT |  no        | default    |
| timeStyle | FULL, LONG, MEDIUM, SHORT,  or  DEFAULT |  no        | default    |
| pattern   |  Custom format mode                         |  no        |  nothing          |
| var       |  The name of the variable that stores the formatted date                 |  no        |  Show on page  |
| scope     |  Store the range of formatted log variables               |  no        |  page        |

#####  Example 

<fmt:parseDate value="2020-01-06" type="date" />

<fmt:parseDate value="2020/01/06" pattern="yyyy/MM/dd" />

版权声明
本文为[Ah, floating]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201209150402391a.html