JSTL Format Tag?

  • 다국어 처리, 날짜 숫자를 formatting 할 경우 format tag 사용하면 편하다.

Multi-lingual App

i18n-messages.jsp

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
35
36
37
38
39
40
41
42
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>


<c:set var="theLocale"
value="${not empty param.theLocale ? param.theLocale : pageContext.request.locale}"
scope="session" />

<fmt:setLocale value="${theLocale}"/>

<fmt:setBundle basename="com.javit.jsp.tagdemo.i18n.resources.mylabels" />


<html>

<body>

<a href="i18n-messages-test.jsp?theLocale=en_US">English (US)</a>

<a href="i18n-messages-test.jsp?theLocale=es_ES">Spanish (ES)</a>

<a href="i18n-messages-test.jsp?theLocale=de_DE">German (DE)</a>


<hr>


<fmt:message key="label.greeting" /> <br/><br/>

<fmt:message key="label.firstname" /> <i>Jay</i> <br/>

<fmt:message key="label.lastname" /> <i>Chung</i> <br/><br/>

<fmt:message key="label.welcome" /> <br/>

<hr>

Selected locale : ${theLocale}

</body>

</html>
Resource 파일

com.javit.jsp.tagdemo.i18n.resources

mylabels.properties

1
2
3
4
label.greeting=Howdy
label.firstname=First Name
label.lastname=Last Name
label.welcome=Welcome to the App Transer.

mylabels_es_ES.properties

1
2
3
4
label.greeting=Hola
label.firstname=Nombre de pila
label.lastname=Apellido
label.welcome=Bienvenido a la aplicación Transer.

mylabels_de_DE.properties

1
2
3
4
label.greeting=Hallo
label.firstname=Vorname
label.lastname=Nachname
label.welcome=Willkommen beim App Transer.

Table of Contents

  1. JSTL Format Tag?
    1. Multi-lingual App
      1. Resource 파일