gwooden_코린이

fmt 태그 사용해보기 본문

JSP&Servlet

fmt 태그 사용해보기

gwooden22 2023. 1. 26. 14:20
728x90

fmt 태그

<fmt:formatNumber> 태그

<fmt:formatNumber value="값(숫자)"

                               [type="number | currency | percent"]

                               [pattern="패턴"]#,##0

                               [currencySymbol="화폐단위"]

                               [groupingUsed="true | false"] //천단위 구분기호 true(기본값)

                               [var="변수명"]

                               [scope="유효범위"]

</fmt:formatNumber>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<fmt:formatNumber value="123456.78"/><br>
	<fmt:formatNumber value="123456.78" groupingUsed="false"/><br>
	<fmt:formatNumber value="0.5" type="percent"/><br>
	<fmt:formatNumber value="123456" type="currency"/><br>
	<fmt:formatNumber value="123456" type="currency" currencySymbol="$" /><br>
	<fmt:formatNumber value="123456.789" pattern="#,##0.0"/><br>
	<fmt:formatNumber value="123456.789" pattern="#,##0.00" var="num"/><br>
	${num}
</body>
</html>

<fmt:formatDate> 태그

<fmt:formatDate value="날짜/시간"

                               [type="time | date | both] //시간 | 날짜 | 둘다

                               [dateStyle="default | short | medium | long | full"]

                               [timeStyle="default | short | medium | long | full"]

                               [pattern="패턴"]

                               [timeZone="타임존"]

                               [var="변수명"]

                               [scope="유효범위"]

</fmt:formatDate>

 

 

<fmt:setTimeZone> 태그

<fmt:setTimeZone value="timezone"

                               [var="변수명"]

                               [scoppe="유효범위"]/>

 

</fmt:timeZone value="timezone">

</fmt:timeZone>

 

<fmt:setLocal> 태그

<fmt:setLocal value="언어코드_국가코드"/>

<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<c:set var="now" value="<%= new Date() %>"/>
	now : ${now}<br>
	date : <fmt:formatDate value="${now}" type="date"/><br>
	time : <fmt:formatDate value="${now}" type="time"/><br>
	both : <fmt:formatDate value="${now}" type="both"/><br>
	<br>
	default : <fmt:formatDate value="${now}" type="both" dateStyle="default" timeStyle="default"/><br>
	short : <fmt:formatDate value="${now}" type="both" dateStyle="short" timeStyle="short"/><br>
	medium : <fmt:formatDate value="${now}" type="both" dateStyle="medium" timeStyle="medium"/><br>
	long : <fmt:formatDate value="${now}" type="both" dateStyle="long" timeStyle="long"/><br>
	full : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/><br>
	<br>
	
	pattern : <fmt:formatDate value="${now}" type="both" pattern="yyyy년MM월dd일hh시mm분ss초"/><br>
	
	<br>
	<h1>tiemzone</h1>
	한국 : <fmt:formatDate value="${now}" type="both"/><br>
	
	<fmt:timeZone value="GMT">
		런던 : <fmt:formatDate value="${now}" type="both"/><br>
	</fmt:timeZone>
	
	<fmt:timeZone value="CET">
		파리 : <fmt:formatDate value="${now}" type="both"/><br>
	</fmt:timeZone>
	
	<h1>로케일 설정</h1>
	톰켓 서버 로케일 : <%=response.getLocale() %><br>
	통화 : <fmt:formatNumber value="10000" type="currency"/><br>
	날짜 : <fmt:formatDate value="${now}"/><br>
	<br>
	<fmt:setLocale value="ja_jp"/>
	변경 후 로케일 : <%=request.getLocale() %><br>
	통화 : <fmt:formatNumber value="10000" type="currency"/><br>
	날짜 : <fmt:formatDate value="${now}"/><br>
	<br>
	<fmt:setLocale value="en_us"/>
	변경 후 로케일 : <%=request.getLocale() %><br>
	통화 : <fmt:formatNumber value="10000" type="currency"/><br>
	날짜 : <fmt:formatDate value="${now}"/><br>
	
</body>
</html>

<fmt:bundle> 태그

리소스 번들 . properties

한국어 페이지 / 영어 페이지

 

http://propedit.sourceforge.jp/eclipse/updates/ 

 

Downloading File /eclipse/updates - Properties Editor - OSDN

Free download page for Project Properties Editor's updates.This editor can directly edit property files written in Unicode reference characters, eliminating the need to convert to Unicode. In a...

osdn.net


<fmt:message key="키이름" [bundle="setBundle 이름"]

                                                 [var="변수명"]

                                                 [scope="유효범위"]/>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<fmt:bundle basename="bundle.test">
		<fmt:message key="name"/><br>
		<fmt:message key="title"/><br>
	</fmt:bundle>
	<h1>새로 추가한 내용</h1>
	<fmt:bundle basename="bundle.test" prefix="user_">
		<fmt:message key="id" /><br>
		<fmt:message key="pw" var="pw"/><br>
		${pw}<br>
	</fmt:bundle>
	<h1>번들태그 밖</h1>
		<fmt:message key="id" /><br>
		${pw}

</body>
</html>


<fmt:setBundle basename="번들경로.파일명"

                                 var="변수명"

                                 [scope="유효범위"]/>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<fmt:bundle basename="bundle.test">
		<fmt:message key="name"/><br>
		<fmt:message key="title"/><br>
	</fmt:bundle>
	<h1>새로 추가한 내용</h1>
	<fmt:bundle basename="bundle.test" prefix="user_">
		<fmt:message key="id" /><br>
		<fmt:message key="pw" var="pw"/><br>
		${pw}<br>
	</fmt:bundle>
	<h1>번들태그 밖</h1>
		<fmt:message key="id" /><br>
		${pw}
		
	<h1>setBundle</h1>
	<fmt:setBundle basename="bundle.test" var="test"/>
	
	<fmt:message key="name" bundle="${test}" /><br>
	<fmt:message key="title" bundle="${test}" /><br>

</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<fmt:setLocale value='<%=request.getParameter("lang")%>' />
	<fmt:setBundle basename="bundle.loginBundle" var="lb" />

	<h1>
		<fmt:message bundle="${lb}" key="title" />
	</h1>
	<a href="login.jsp?lang=ko">한국어</a> | <a href="?lang=en">English</a>
	<br>
	<form method="get" action="">
		<fmt:message bundle="${lb}" key="id" />
		: <input type="text" name="id"> <br>
		<fmt:message bundle="${lb}" key="pw" />
		: <input type="password" name="pw"> <br>
		<input type="submit" value='<fmt:message bundle="${lb}" key="btn" />'>
	</form>
</body>
</html>

728x90
Comments