리소스 properties 파일 이용하기
3가지 방법
1. fmt bundle 이용
<fmt:setLocale value="ko_KR"/>
<fmt:setBundle basename="resource" var="lang" />
<fmt:message key="fruits.apple" bundle="${lang}" />
</body>
</html>
파일 위치는 /WEB-INF/src바로 밑에
* resource.properties
fruits.apple=apple
fruits.strawberry=strawberry
fruits.banana=banana
2. 프로젝트 \WEB-INF\web.xml 안에 추가할수도 있네요
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>JeongMessageBundle</param-value>
</context-param>
파일위치 : classes\JeongMessageBundle.properties
3. JSP 에서 사용
Copy properties file in WEB-INF/classes folder
Suppose we have file commonVariable.properties in WEB-INF/classes folder
# forum path and properties forum.path=forum forum.url=forum forum.database=jspforum forum.use=yes
JSP which is getting values from ResourceBundle properties file
resource.jsp
<%@ page language="java" import="java.util.*" %> <% ResourceBundle resource = ResourceBundle.getBundle("commonVariable"); /// commonVariable.properties file will be in WEB-INF/classess folder String sPath=resource.getString("forum.path"); String sName=resource.getString("forum.database"); System.out.println(sPath); System.out.println(sName); %>
'JSP' 카테고리의 다른 글
유용한 크롬 확장프로그램 (0) | 2013.12.05 |
---|---|
[tag lib] tld파일설정 및 커스텀 태그 정리 (0) | 2013.06.19 |
[펌] JSP 버전 확인 방법 (0) | 2013.06.19 |
<fmt: bundle>태그와 <fmt:message>태그 등 (0) | 2013.06.05 |
[펌] <jsp:include page=...>과 <@include file=...>의 차이 (0) | 2013.04.29 |