[JSTL] Format

- 다국어와 날짜/시간을 표현

- 선언

[%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %]

기능
액션 태그
Prefix

Locale 설정
setLocale, requestEncoding
fmt

메시지 처리
Bundle, message(param), setBundle

숫자 날짜 형식
formatNumber, formatDate, parseDate,

parseNumber, setTimeZone, timeZone


- [fmt:requestEncoding/]은 페이지에 인코딩이 적용된 경우, 파라미터의 인코딩을 조정하기 위해서 사용한다.

- [fmt:bundle/]과[fmt:message/]는 번들에 있는 키값을 불러온다.



예)testBundle.property파일을 읽어와 testBundle변수에 지정한 뒤에 [fmt:message/]를 통해서 키에 접근하여 출력하는 소스

[%@ taglib uri=http://java.sun.com/jstl/fmt" prefix="fmt" %]

[ fmt:setLocale value="ko"/]

[ fmt:setBundle var="testBundle" basename="test.msg.TestBundle"/]

[ fmt:message bundle="${testBundle}" key="greeting"/][br.

[ fmt:message bundle="${testBundle}" key="admin"/][br]







[ fmt:formatNumber/]와 [ fmt:parseNumber/]로 숫자,통화,퍼센트 표시

[fmt:formatNumber의 속성 ]

속성
동적값
Type
설명

value
true
String or Numer
형식화될 수치

type
true
String
숫자,통화,퍼센트 중 표시 지정

{number|currency|percent}

pattern
true
String
사용자가 지정한 형식 패턴

currencyCode
true
String
ISO 4217 통화코드, 통화형식일 때만 적용(type="currency")

currencySymbol
true
String
통화기호, 통화 형식일 때만 적용(type="currency")

groupingUsed
true
boolena
형식 출력에 그룹 분리기호를 포함할지 여부

maxIntegerDigits
true
int
형식 출력에서 integer 최대 자리 수

minIntegerDigits
true
int
형식 출력에서 integer 최소 자리 수

maxFractionDigits
true
int
형식 출력에서 소수점 이하 최대 자리수

minFractionDigits
true
int
형식 출력에서 소수점 이하 최소 자리수

var
true
int
형식 출력 결과 문자열을 담는 scope에 해당하는 변수

Scope
true
int
var의 scope




[fmt:parseNumber의 속성]

속성
동적값
Type
설명

value
true
String or Number
파싱할 수치

type
true
String
숫자,통화,퍼센트 중 표시 지정

{number|currency|percent}

pattern
true
String
사용자가 지정한 형식 패턴

parseLocale
true
String or java.util.Locale
파싱 작업의 기본 형식 패턴 (숫자,통화,퍼센트 각각)을 제공하는 Locale

integerOnly
true
boolean
주어진 값에서 integer 부분만 파싱할지 여부를 지정

var
false
String
파싱 결과(java.lang.Number 타입)를 담는 scope에 해당하는 변수명

scope
false
String
var의 scope


예)

[fmt:formatNumber value="1234567.89" type="number"/]

[fmt:formatNumber value="1234567.89" type="currency"/]

[fmt:formatNumber value="1234567.89" type="percent"/]

[fmt:formatNumber value="1234567.89" pattern=".000"/]

[fmt:formatNumber value="1234567.89123" pattern="#,#00.0#"/]




[fmt:formatDate의 속성]

속성
동적값
Type
설명

value
true
Java.util.Date
헝식화될 Date와 time

type
true
String
형식화할 데이터가 시간, 날짜, 혹은 둘 다인지 지정

dateStyle
true
String
미리 정의된 날짜 형식, java.text.DateFormat클래스에 정의된 문법을 따름, type="date", type="both", type 속성이 생략된 경우 사용


timeStyle
true
String
미리정의된 날짜 형식, java.text.DateFormat클래스에 정의된 문법을 따름, type="time", type="both", type 속성이 생략된 경우 사용

pattern
true
String
사용자 지정 형식 스타일

timeZone
true
String or java.util.TimeZone
형식화 시간에 나타날 타임존

var
false
String
형식 출력 결과 문자열을 담는 scope에 해당하는 변수명

scope
false
String
var의 scope


예)

[fmt:formatDate value="${event.startTime}" type="both" pattern="MM/dd/yy hh:mm a"/]




[fmt:parseDate의 속성]

속성
동적값
Type
설명

value
true
Java.util.Date
파싱할 Date와 time

type
true
String
파싱할 데이터가 시간, 날짜, 혹은 둘 다인지 지정

dateStyle
true
String
미리 정의된 날짜 형식, java.text.DateFormat클래스에 정의된 문법을 따름, type="time", type="both", type 속성이 생략된 경우 사용


timeStyle
true
String
미리정의된 날짜 형식, java.text.DateFormat클래스에 정의된 문법을 따름, type="time", type="both", type 속성이 생략된 경우 사용

pattern
true
String
사용자 지정 형식 스타일

timeZone
true
String or java.util.TimeZone
형식화 시간에 나타날 타임존

parseLocale
false
String or java.util.Locale
파싱하는 동안 적용될 미리 정의된 형식 스타일의 Locale

var
false
String
파싱 결과(java.util.Date)를 담는 scope에 해당하는 변수명

scope
false
String
var의 scope


예)

[jsp:useBean id="now" class="java.util.Date"/]

[c:out value="${now}"/]

[fmt:formatDate value="${now}" type="date"/]

[fmt:formatDate value="${now}" type="time"/]

[fmt:formatDate value="${now}" type="both"/]

[fmt:formatDate value="${now}" type="both"

dateStyle="logn" timeStyle="long"/]

댓글

이 블로그의 인기 게시물

[LINUX] CentOS 부팅시 오류 : UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY

[MSSQL] 데이터베이스가 사용 중이어서 배타적으로 액서스할 수 없습니다

구글코랩) 안전Dream 실종아동 등 검색 오픈API 소스를 공유합니다. (구글드라이브연동, 이미지 수집 소스)