Internationalization Tag Library in JSP
What is Internationalization Tag Library in JSP?
Explanation
Internationalization Tag Library or 118N Tag library lists the tags that confirm the client locale settings for formatting and parsing client sensitive data like currency, date, etc in a locallized or customized manner. The following table lists all the tags that confirm to 118N standards and is used with a prefix "fmt".
Syntax:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Setting Locale Function :
Tags | Description |
---|
setLocale, | SetLocale tag is used set the linguistic conventions of a particular region |
requestEncoding
| requestEncoding tag is used to set character encoding. |
Messaging Function:
Tags | Description |
---|
bundle, | bundle tag is used to set the resource bundle for a given tag body, |
message, | Message tag allows you to retrieve text messages from a locale-specific resource bundle and display it on a JSP page. |
setBundle | setBundle is to set the localization context in a variable . |
Number and Date Formatting Function:
Tags | Description |
---|
formatNumber, | formatNumber is used to convert a number using the java class instance |
formatDate | formatDate is used to convert a number using the java class instance |
setTimeZone, parseDate, parseNumber | All these tags needs to specify the date, number explicitly to convert into an object. |
Example :
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"
prefix="fmt" %>
<p>Convert the number 14.3 with 4 decimal places</p>
Formatting: <fmt:formatNumber value="123.4" type="NUMBER"
minFractionDigits="4" />
Result :
Convert the number 14.3 to have 4 decimal places
Formatting: 123.4000
In the above example we have used the 118N tag to add "4" decimal places to the number given. Example :
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:useBean id="dat" class="java.util.Date" />
<fmt:formatDate value="${dat}" type="time" />
Result :
1:44:40 PM
In the above we have used the "<:jsp:useBean/>" tag to include the java date class, using the format tag attribute "type" the time alone is displayed.