Usage collation of JSTL fmt of format formatted tags commonly used in JSP

  • 2021-09-24 23:18:28
  • OfStack

The JSTL tag provides support for internationalization (I18N), which can display different languages depending on the domain of the requesting client. It also provides methods for formatting data and dates. Implementing these features requires an I18N format tag library (I18N-capable formation tags liberary). The method of introducing this tag library is as follows:
< %@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" % >
The I18N format tag library provides 11 tags, which can be functionally divided into three categories as follows:
(1) Digital date formatting. formatNumber tag, formatData tag, parseNumber tag, parseDate tag, timeZone tag, setTimeZone tag.
(2) Read the message resource. bundle tag, message tag, setBundle tag.
(3) Internationalization. setlocale tag, requestEncoding tag.
The functions and usage of these labels will be described in detail.

< fmt:formatNumber > Label

Formatting numbers as numbers, currencies, or percentages by region or custom


<fmt:formatNumber value="number" [type={number|currency|percent|}]

[pattern="pattern"]

[currencyCode="currencyCode"]

[currentSymbol="currentSymbol"]

[groupingUsec="{true|false}"]

[maxIntergerDigits="maxIntergerDigits"]

[minIntergerDigits="minIntergerDigits"]

[maxFractionDigits="maxFractionDigits"]

[minFractionDigits="minFractionDigits"]

[var="varname"]

[scope="page|request|session|application"]

 />


<%@page language="java" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
  <head>
    <title>FormatNumber Label usage </title>
  </head>
  <body>
    <h1>FormatNumber Label usage </h1>
    <fmt:setLocale value="fr_fr" />
    France:<fmt:formatNumber value="123456789.012"/>
    <fmt:setLocale value="zh_cn" />
    China:<fmt:formatNumber value="123456789.012"/>
    <fmt:setLocale value="de_de" />
    Germany:<fmt:formatNumber value="123456789.012"/>
     
  </body>
</html>

< fmt:parseNumber / > Label

Used to convert a number, currency, or percentage of string type to a number type


<fmt:parseNumber value="numberString" [type={number|currency|percent|}]

[pattern="pattern"]

[parseLocale="parseLocale"]

[integerOnly="{false|true}"]

[var="varname"]

[scope="page|request|session|application"]

 />

< fmt:formatDate / > Label

Used to convert date type to string type date


<fmt:formatDate value="number" [type={time|date|both}]

[pattern="pattern"]

[dateStyle="{default|short|medium|long|full}"]

[timeStyle="{default|short|medium|long|full}"]

[timeZone="timeZone"]

[var="varname"]

[scope="page|request|session|application"]

 />

< fmt:parseDate / > Label

Used to convert time or date of string type to datetime type


<fmt:parseDate value="date" [type={time|date|both}]

[pattern="pattern"]

[dateStyle="{default|short|medium|long|full}"]

[timeStyle="{default|short|medium|long|full}"]

[timeZone="timeZone"]

[var="varname"]

[scope="page|request|session|application"]

 />

< fmt:setTimeZone / > Label

Used to set the default time zone or store the time zone in the property range


<fmt:setTimeZone value="timezone" [var="varname"] [scope="{page|request|session|application}"] />
< fmt:timeZone / > Label Used to temporarily set the time zone

<fmt:timeZone value="timeZone">

 Ontology content 

</fmt:timeZone>

< fmt:setLocale / > Label

Used to set the user's regional language


<fmt:setLocale value="locale" [variant="variant"] [scope="{page|request|session|application}"] />

< fmt:requestEncoding / > Label Set the encoding format of the received string

<fmt:requestEncoding value="charsetName" />

< fmt:setBundle / > Label

It is used to set the default data source, or it can be stored in 1 range for use when necessary


<fmt:setBundle basename="basename" [var="varname"] [scope="{page|request|session|application}"] />

< fmt:message / > Label

Used to get values from the specified resource file by index


<fmt:message key="messageKey" [bundle="resourceBundle"] [var="varname"] [scope="{page|request|session|application}"] />

< fmt:param / > Label

Used to pass parameters (in case you may need to set parameters dynamically when getting information from a resource file)


<fmt:param value="messageParameter" />

No ontology content


<fmt:param value="messageParameter" > Ontological content 

 Parameter 

</fmt:param>

< fmt:bundle / > Label

Used to set the data source


<fmt:bundle basename="basename" [prefix="prefix"] >

 Ontology content <fmt:message>

</fmt:bundle>


Related articles: