FMT, I18N - 국제화(Internationalization)
기능 : 지역, 메시지 형식, 숫자 및 날짜형식
접두어(Prefix) : fmt
directive : <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
JSTL 국제화 지역화 태그로 다국어 문서를 처리할 때 유용하고, 날짜와 숫자 형식을 다룰 때 사용된다.
목차
setLocale
다국어를 지원하는 페이지를 만들 경우 ResourceBundle로 불러오는 *.properties 파일들과 연계되어서 사용한다.
<fmt:setLocale value="locale" [variant="variant"] [scope="{page|request|session|application}"]/>
value의 locale 값은 http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt 언어코드와 http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html 국가코드로 이루어진다. 생략될경우 톰캣 서버의 기본 값으로 설정이 되고, 둘 중에 하나만 사용할 수도 있다.
<%@ page contentType = "text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.comjsp/jsp/jstl/fmt" prefix="fmt"%>
<pre>
default locale : <%= response.getLocale() %>
set locale : ko <fmt:setLocale value="ko" />
now: <%= response.getLocale() %>
set locale : ja <fmt:setLocale value="ja" />
now: <%= response.getLocale() %>
set locale : en <fmt:setLocale value="en" />
now: <%= response.getLocale() %>
</pre>
requestEncoding
request.setCharacterEncoding() 역할을 한다.
<fmt:requestEncoding [value="charsetName"]/>
<%@ page contentType = "text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
<%@ page contentType = "text/html; charset=utf-8" %> <%@ taglib prefix="c" uri="http://java.sun.comjsp/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head><title>JSTL fmt 예제 - bundle , message</title></head> <body> <fmt:bundle basename="bundle.testBundle"> <fmt:message key="name"/> <p/> <fmt:message key="message" var="msg"/> <c:out value="${msg}"/> </fmt:bundle> </body> </html> |
[currencyCode="currencyCode"] [currencySymbol="currencySymbol"]
[groupingUsed="{true|false}"] [maxIntegerDigits="maxIntegerDigits"]
[minIntegerDigits="minIntegerDigits"] [maxFractionDigits="maxFractionDigits"]
[minFractionDigits="minFractionDigits"] [var="varName"]
[scope="{page|request|session|application}"]/>
Syntax 2: 형식에 맞출 수치가 body에 있는 경우
<fmt:formatNumber [type="{number|currency|percent}"]
[pattern="customPattern"] [currencyCode="currencyCode"]
[currencySymbol="currencySymbol"] [groupingUsed="{true|false}"]
[maxIntegerDigits="maxIntegerDigits"] [minIntegerDigits="minIntegerDigits"]
[maxFractionDigits="maxFractionDigits"] [minFractionDigits="minFractionDigits"]
[var="varName"] [scope="{page|request|session|application}"]>
형식화될 수치
</fmt:formatNumber>
<fmt:formatNumber value="1700600"/> // 1,700,600
<fmt:formatNumber value="1700600" type="currency" groupingUsed="true"/> // ₩1,700,600
<fmt:formatNumber value="50" type="percent" groupingUsed="false"/> // 5000%
<fmt:formatNumber value="1670400" type="currency" currencySymbol="&"/> // &1,670,400
<fmt:formatNumber value="999" minIntegerDigits="5" minFractionDigits="2"/> // 00,999.00
|
속성 |
동적 |
Type |
설명 |
|
value |
true |
String 또는 Number |
형식화될 수치 |
|
type |
true |
String |
숫자, 통화, 퍼센트 중 어느 것으로 표시할 지 지정 {number|currency|percent} |
|
pattern |
true |
String |
사용자가 지정한 형식 패턴. |
|
currencyCode |
true |
String |
ISO 4217 통화 코드 (통화 형식일 때만 적용) (type="currency") |
|
currencySymbol |
true |
String |
통화 기호 (통화 형식일 때만 적용) (type="currency") |
|
groupingUsed |
true |
boolean |
형식 출력에 그룹 분리기호를 포함할지 여부 (기본값은 true) |
|
maxIntegerDigits |
true |
int |
형식 출력에서 integer 최대 자리 수 |
|
minIntegerDigits |
true |
int |
형식 출력에서 integer 최소 자리 수 |
|
maxFractionDigits |
true |
int |
형식 출력에서 소수점 이하 최대 자리 수 |
|
minFractionDigits |
true |
int |
형식 출력에서 소수점 이하 최소 자리 수 |
|
var |
false |
String |
형식 출력 결과 문자열을 담는 scope에 해당하는 변수명 |
|
scope |
false |
String |
var의 scope |
parseNumber
반대로 정해진 패턴을 문자열에서 수치를 파싱해내는 태그
Syntax 1: body가 없는 경우
<fmt:parseNumber value="numericValue"
[type="{number|currency|percent}"] [pattern="customPattern"]
[parseLocale="parseLocale"] [integerOnly="{true|false}"]
[var="varName"] [scope="{page|request|session|application}"]/>
Syntax 2: 파싱할 수치를 body에 갖고 있는 경우
<fmt:parseNumber [type="{number|currency|percent}"]
[pattern="customPattern"] [parseLocale="parseLocale"]
[integerOnly="{true|false}"] [var="varName"]
[scope="{page|request|session|application}"]>
파싱할 수치
</fmt:parseNumber>
|
속성 |
동적 |
Type |
설명 |
|
value |
true |
String 또는 Number |
파싱할 수치 |
|
type |
true |
String |
숫자, 통화, 퍼센트 중 어느 것으로 표시할 지 지정 {number|currency|percent} |
|
pattern |
true |
String |
사용자가 지정한 형식 패턴 |
|
parseLocale |
true |
String 또는 java.util.Locale |
파싱 작업의 기본 형식 패턴(숫자, 통화, 퍼센트 각각)을 제공하는 Locale |
|
integerOnly |
true |
boolean |
true일 경우 주어진 값에서 Integer 부분만 파싱 |
|
var |
false |
String |
파싱 결과(java.lang.Number)를 담는 scope에 해당하는 변수명 |
|
scope |
false |
String |
var의 scope |
|
속성 |
동적 |
Type |
설명 |
|
value |
true |
java.util.Date |
형식화 될 Date와 Time |
|
type |
true |
String |
형식화 할 데이터가 시간, 날짜, 혹은 시간과 날짜인지 지정 |
|
dateStyle |
true |
String |
미리 정의된 날짜 형식. java.text.DateFormat 클래스에 정의된 문법을 따른다. type 속성이 생략되었거나 date 혹은 body일 때 사용 |
|
timeStyle |
true |
String |
미리 정의된 시간 형식. type 속성이 time 혹은 body일 때 사용 |
|
pattern |
true |
String |
사용자 지정 형식 스타일 |
|
timeZone |
true |
String 또는 java.util.TimeZone |
형식화 시간에 나타날 타임 존 |
|
var |
false |
String |
형식 출력 결과 문자열을 담는 scope에 해당하는 변수명 |
|
scope |
false |
String |
var의 scope |
|
속성 |
동적 |
Type |
설명 |
|
value |
true |
java.util.Date |
파싱할 Date와 Time |
|
type |
true |
String |
파싱할 데이터가 시간, 날짜, 혹은 시간과 날짜인지 지정 |
|
dateStyle |
true |
String |
미리 정의된 날짜 형식. java.text.DateFormat 클래스에 정의된 문법을 따른다. type 속성이 생략되었거나 date 혹은 body일 때 사용 |
|
timeStyle |
true |
String |
미리 정의된 시간 형식 type 속성이 time 혹은 body일 때 사용 |
|
pattern |
true |
String |
사용자 지정 형식 스타일 |
|
timeZone |
true |
String 또는 java.util.TimeZone |
형식화 시간에 나타날 타임 존 |
|
parseLocale |
true |
String 또는 java.util.Locale |
파싱하는 동안 적용될 미리 정의된 형식스타일의 Locale |
|
var |
false |
String |
파싱 결과(java.util.Date)를 담는 scope에 해당하는 변수명 |
|
scope |
false |
String |
var의 scope |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 |
<%@ page contentType = "text/html; charset=utf-8" %> <%@ page pageEncoding="utf-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <!DOCTYPE html><html><head><title></title></head><body> <pre> <fmt:setLocale value="ko_KR"/> number : <fmt:formatNumber value="9876543.61" type="number"/> currency : <fmt:formatNumber value="9876543.61" type="currency"/> percent : <fmt:formatNumber type="percent">9876543.61</fmt:formatNumber> pattern=".000" :<fmt:formatNumber value="9876543.61" pattern=".000" /> pattern="#,#00.0#":<fmt:formatNumber value="9876543.612345" pattern="#,#00.0#"/> <jsp:useBean id="now" class="java.util.Date"/> <c:out value="${now}"/> date : <fmt:formatDate value="${now}" type="date"/> time : <fmt:formatDate value="${now}" type="time"/> both : <fmt:formatDate value="${now}" type="both"/> default : <fmt:formatDate value="${now}" type="both" dateStyle="default" timeStyle="default"/> short : <fmt:formatDate value="${now}" type="both" dateStyle="short" timeStyle="short" /> medium : <fmt:formatDate value="${now}" type="both" dateStyle="medium" timeStyle="medium" /> long : <fmt:formatDate value="${now}" type="both" dateStyle="long" timeStyle="long" /> full : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full" /> pattern="yyyy년MM월dd일 HH시mm분ss초" <fmt:formatDate value="${now}" type="both" pattern="yyyy년MM월dd일 HH시mm분ss초"/> </pre></body></html> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
<%@ page contentType = "text/html; charset=utf-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <!DOCTYPE html><html><head><title></title></head><body> <pre> <fmt:setLocale value="ko_KR"/> <jsp:useBean id="now" class="java.util.Date"/> default : <c:out value="${now}"/> Korea KST : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/> <fmt:timeZone value="GMT"> Swiss GMT : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/> </fmt:timeZone> <fmt:timeZone value="GMT-8"> NewYork GMT-8 : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/> </fmt:timeZone> </pre></body></html> |
'JSP' 카테고리의 다른 글
| jsp -> excel 저장시 숫자형 자릿수 문제에 대해 (0) | 2014.03.25 |
|---|---|
| JSTL: fn (0) | 2014.03.25 |
| JSTL: core (0) | 2014.03.25 |
| JSTL (0) | 2014.03.25 |
| [html] 마우스 오버시 이미지 변경 속에 버튼 (0) | 2014.03.18 |
| 마우스 오버시 tr 색상 변경 (0) | 2014.03.18 |
| [html] 테이블 TD 또는 TR 마우스 오버시 색상 변경하기 (0) | 2014.03.18 |
| EL 에서 substring 사용 (0) | 2014.02.12 |