Internationalization tags are the second most used tags in JSTL. The most used tags are core tags, as you can refer to in my last post.
2022.09.17 - [JSP] - JSP) JSTL (JSP Standard Tag Library) - Core tags
Internationalization tags are related to numbers, dates, and timezone. The example tag with the URI is like this :
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
The prefix value is "fmt" and the URI ends with "fmt" which refers to the internationalization tag.
For your better understanding, let us look through some simple examples.
numberFormat Tag
<%@ page contentType = "text/html; charset=utf-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head><title>numberFormat Tag</title></head>
<body>
<c:set var="now" value="<%= new java.util.Date() %>" />
${now }<br>
<c:out value="${now }"/><br>
<fmt:formatDate value="${now}" type="date" dateStyle="full" /> <br> <!-- in detail -->
<fmt:formatDate value="${now}" type="date" dateStyle="short" /> <br> <!-- simple -->
<fmt:formatDate value="${now}" type="time" /> <br>
<fmt:formatDate value="${now}" type="both"
dateStyle="full" timeStyle="full" /> <br>
<fmt:formatDate value="${now}" pattern="z a h:mm" /> <br><br> <!-- z: timezone a: am/pm -->
<fmt:formatDate value="${now}" pattern="MM/dd/yy EEEE h:mm a z"/><br>
</body>
</html>
timeZone tag
<%@ page contentType = "text/html; charset=utf-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head><title>timeZone Tag</title></head>
<body>
<c:set var="now" value="<%= new java.util.Date() %>" />
<fmt:formatDate value="${now}" type="both"
dateStyle="full" timeStyle="full" />
<br>
<fmt:timeZone value="Hongkong">
<fmt:formatDate value="${now}" type="both"
dateStyle="full" timeStyle="full" />
</fmt:timeZone>
<br>
<fmt:timeZone value="America/New_York">
<fmt:formatDate value="${now}" type="both"
dateStyle="full" timeStyle="full" />
</fmt:timeZone>
<br>
<fmt:timeZone value="Asia/Seoul">
<fmt:formatDate value="${now}" type="both"
dateStyle="full" timeStyle="full" />
</fmt:timeZone>
<br>
</body>
</html>
formatNumber Tag
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>formatNumber Tag</title>
</head>
<body>
<c:set var="price" value="10000" />
<fmt:formatNumber value="${price}" type="number" var="numberType" />
Number: ${numberType} <!-- Variable name -->
<br> KRW:
<fmt:formatNumber value="${price}" type="currency" currencySymbol="\\" />
<br> USD:
<fmt:formatNumber value="${price}" type="currency" currencySymbol="$" />
<br> Percentage:
<fmt:formatNumber value="${price}" type="percent" groupingUsed="true" />
<br> Percentage:
<fmt:formatNumber value="${price}" type="percent" groupingUsed="false" />
<br> Pattern:
<fmt:formatNumber value="${price}" pattern="00000000.00" />
</body>
</html>
'Java > JSP' 카테고리의 다른 글
JSP) JSTL - Function tags / SQL tags (0) | 2022.09.19 |
---|---|
JSP) JSTL (JSP Standard Tag Library) - Basic / Core tags (0) | 2022.09.17 |
JSP) EL(Expression Language) (0) | 2022.09.16 |
JSP) Model2 - Java Servlet 1 (0) | 2022.09.15 |
JSP) Model1 vs Model2 (0) | 2022.09.15 |