JSTL (i18n)

Source: Internet
Author: User
Tags i18n locale time and date

i18n
Used to write internationalized Web programs
taglib:<%@ taglib uri= "http://java.sun.com/jsp/jstl/fmt" prefix= "FMT"%>

1, <fmt:setLocale>
Used to set the local language of the user and save the specified locale to the javax.servlet.jsp.jstl.fmt.local configuration variable
Config.find (Pagecontext,config.fmt_locale) can get LOCALE properties
<fmt:setlocale value= "locale" variant= "Variant" scope= "Page|request|session|application"/>
Variant: Vendor or browser code win, MAX, POSIX
Generally placed at the top of the page, other tags can be obtained by Servletrequest.getlocale () locale
<fmt:setlocale value= "en"/>
<fmt:setlocale value= "Zh_cn"/>

2, <fmt:bundle>
Create the i18n local context environment for which the label body is used
<fmt:bundle basename= "basename" prefix= "prefix" >
Body
</fmt:bundle>
BaseName: Name of resource bundle
Prefix: Specifies the prefix to add before the <fmt:message> label's message key


3, <fmt:setBundle>
Create a i18n local context and save it to a range variable or javax.servlet.jsp.jstl.fmt.localizationContext configuration variable
<fmt:setbundle basename= "basename" var= "varname" scope= ""/>
BaseName: Base name of resource bundle
var: the name of the saved local context range variable that was exported, the type is Javax.servlet.jsp.jstl.fmt.localizationContext

4, <fmt:message>
Finds the value of a specified key from the resource bundle to display localized information
<fmt:message key= "key" bundle= "ResourceBundle" var= "VarName" scope= ""/>
<fmt:message key= "key" bundle= "ResourceBundle" var= "VarName" "scope=" ">
<fmt:param>
</fmt:message>
<fmt:message bundle= "ResourceBundle" var= "VarName" scope= ""/>
Key
<fmt:param>
</fmt:message>

5, <fmt:param>
Provide a parameter for <fmt:message> use
<fmt:param value= "Messageparameter"/>
<fmt:param>
Body Content
</fmt:param>
Can be used to replace parameters in a message

6, <fmt:requeatEncoding>
Set the character encoding of the request
<fmt:requestencoding value= "CharsetName"/>
==request.setcharacterencoding ();

Format label

1, <fmt:timeZone>
Specifies the time zone in which the body of the label will be formatted or parsed at this time zone
<fmt:timezone value= "TimeZone"/>
Body Content
</fmt:timeZone>
Value:string or TimeZone.

2, <fmt:setTimeZone>
Specify the time zone and save it to a range variable, or to a javax.servlet.jsp.jstl.fmt.timeZone configuration variable
<fmt:settimezone value= "TimeZone" var= "VarName" scope= ""/>
If no Var is implemented, the time zone is saved to the Javax.servlet.jsp.jstl.fmt.timeZone configuration variable.

3.<fmt:formatnumber>
Format numeric values as numbers, currencies, percentages, by region or custom

<fmt:formatnumber value= "value" type= "Number|currency|percent" pattern= "Custompattern"
  Currencycode= "code" currencysymbol= "symbol" groupingused= "True|false" maxintegerdigits= "Max"
  minintegerdigits= "min" maxfractiondigits= "Max" minfractiondigits= "Min" var= "VarName" "scope="/>
<fmt: FormatNumber type= "number|currency|percent" pattern= "Custompattern"
 currencycode= "code" currencySymbol= " Symbol "groupingused=" True|false "maxintegerdigits=" Max "
 minintegerdigits=" min "maxfractiondigits=" Max " minfractiondigits= "min" var= "VarName" scope= ""
 value
</fmt:formatnumber>
pattern:string A custom formatted style that is superior to the Type,java.text.decimalformat
currencycode:string ISO 4271 Currency code for formatting currencies
Currencysymbol:string Currency symbol
Groupingused: whether to include the delimiter for grouping, default true
Maxintegerdigits: The maximum number of digits in the integer portion of the formatted output


4.<fmt:parsenumber>
Converts a formatted string of data, currency, or percentage to a numeric type, as opposed to <fmt:formatNumber>
<fmt:parsenmber value= "value" type "number|currency|percent" pattern= "pattern"
parselocale= "locale" integeronly= "True|false" var= "VarName" scope= ""/>
<fmt:parsenumber type "number|currency|percent" pattern= "pattern"
parselocale= "locale" integeronly= "True|false" var= "VarName" "scope=" ">
Value
</fmt:parseNumber>
Parselocal:string or Locale
integeronly: Resolves only integer parts of numeric values, default False

5.<fmt:formatedate>
Format time and dates according to locale or custom format
<fmt:formatedate value= "value" type= "Date|time|both" datestyle= "Default|short|medium|long|full"
Timestyle= "Default|short|medium|long|full" pattern= "pattern"
Timezone= "zone" var= "VarName" scope= ""/>
Pattern:string custom time and date styles must be derived from Java.text.SimpleDateFormat, and once specified, Type,datestyle,timestyle will be ignored

6.<fmt:parsedate>
Converts the time and date of a formatted string to a date type
<fmt:parsedate value= "value" type= "Time|date|both" datestyle= "" timestyle= "" pattern= ""
Timezone= "parselocale=" Locale "var=" "scope=" "/>"
<fmt:parsedate type= "Time|date|both" datestyle= "timestyle=" "pattern=" "
Timezone= "parselocale=" Locale "var=" "scope=" ">
Value
</fmt:parseDate>


EX:
<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>

<title>jstl:formatting/i18n Support--Italian Locale example</title>
<body bgcolor= "#FFFFFF" >

<fmt:setlocale value= "It_it"/>
<fmt:setbundle basename= "org.apache.taglibs.standard.examples.i18n.Resources" var= "Itbundle" scope= "page"/>
<fmt:message key= "greetingmorning" bundle= "${itbundle}"/>

</body>


<fmt:setlocale value= "de"/>
<fmt:bundle basename= "Org.apache.taglibs.standard.examples.i18n.Resources" >
<fmt:message>
Greetingmorning
</fmt:message>
</fmt:bundle>

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.