Common JSTL fmt (format) label usage in JSP, jstlfmt
The JSTL tag supports internationalization (I18N). It can display different languages based on the region of the client sending the request. You can also format the data and date. The I18N format label Library (I18N-capable formation tags liberary) is required to implement these features ). The method for introducing this tag library is:
<% @ Taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
The I18N format tag Library provides 11 tags, which can be divided into three categories:
(1) format the numeric date. FormatNumber tag, formatData tag, parseNumber tag, parseDate tag, timeZone tag, and setTimeZone tag.
(2) read the message resource. Bundle tag, message tag, and setBundle tag.
(3) internationalization. Setlocale tag and requestEncoding tag.
Next, we will detail the functions and usage of these labels.
<Fmt: formatNumber> label
Format a number into a number, currency, or percentage by region or custom Method
<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>
<Fmt: parseNumber/> label
Converts a number, currency, or percentage of the string type to a numeric 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 the date type to the 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
Converts a string-type time or date to a 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/> tag
Used to set the default time zone or store the time zone in the attribute range
Copy codeThe Code is as follows:
<Fmt: setTimeZone value = "timezone" [var = "varname"] [scope = "{page | request | session | application}"]/>
<Fmt: timeZone/> labelUsed to temporarily set the time zone
<Fmt: timeZone value = "timeZone"> body content </fmt: timeZone>
<Fmt: setLocale/> label
Used to set the regional language of a user
Copy codeThe Code is as follows:
<Fmt: setLocale value = "locale" [variant = "variant"] [scope = "{page | request | session | application}"]/>
<Fmt: requestEncoding/> labelSet the encoding format of the received string
<fmt:requestEncoding value="charsetName" />
<Fmt: setBundle/> tag
It is used to set the default data source or store it in a certain range for use when necessary.
Copy codeThe Code is as follows:
<Fmt: setBundle basename = "basename" [var = "varname"] [scope = "{page | request | session | application}"]/>
<Fmt: message/> label
Used to obtain the value from the specified resource file through the index
Copy codeThe Code is as follows:
<Fmt: message key = "messageKey" [bundle = "resourceBundle"] [var = "varname"] [scope = "{page | request | session | application}"]/>
<Fmt: param/> label
Used to pass parameters (when obtaining information from the resource file, you may need to dynamically set parameters)
<fmt:param value="messageParameter" />
No body content
<Fmt: param value = "messageParameter"> body content parameters </fmt: param>
<Fmt: bundle/> tag
Used to set the data source
<Fmt: bundle basename = "basename" [prefix = "prefix"]> body content <fmt: message> </fmt: bundle>
Articles you may be interested in:
- JSTL core tag usage in JSP
- How to Use JSTL to output content according to different conditions in JSP
- Client verification, common output methods, and basic JSTL usage in the JSP getting started tutorial
- Jsp uses jstl to implement paging instance code
- How to solve the problem of using jstl to import html garbled characters in jsp
- Example of JSP and JSTL obtaining server Parameters
- Jstl exception Analysis on jsp pages