티스토리 뷰

Jsp&Servlet

JSTL

살구르 2017. 1. 31. 14:51

1. core

2. fmt

 -*.properties => 다국어 지원 / DB의 driver, url, id, pwd 지정

 -<fmt:bundle basename="bundle.testBundle"> 

  </fmt:bundle>


ex)fmt:bundle basename="bundle.testBundle"

// testBundle_en.properties

name=손님

message=환영합니다!

 

// testBundle_ko.properties

name=guest

message=Welcome!

 

//jstlEx09.jsp

<%@ page language="java" contentType="text/html; charset=ksc5601"

pageEncoding="EUC-KR"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

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

<fmt:setLocale value="en"/> ===> testBundle_en.properties 가 불러짐

<fmt:bundle basename="bundle.testBundle">

<fmt:message key="name" />

<fmt:message key="message" var="msg" />

<c:out value=" ${msg}" />

</fmt:bundle>

 


위의 properties 파일의 내용을 읽어오는 태그로 fmt:bundle 이 있다.

이 때, basename으로 설정한 properties 파일을 읽어오며, 클라이언트의 언어에 따라 해당하는 properties 파일을 읽어오게 된다.

클라이언트의 언어를 원하는 언어로 설정하기 위해서는 <fmt:setLocale value=""> 로 설정한다.

위의 예에서는 클라이언트의 언어를 en으로 설정하였고,

<fmt:message key=""> 로 해당 언어의 properties 파일에서 key에 해당하는 value를 읽어온다.

만약 <fmt:message key="" var=""> 처럼 var를 지정하면 변수에 저장을 하는 것이고, 이를 <c:out value="변수 이름"> 으로 출력해주었다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/05   »
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
글 보관함