언어 설정
날짜와 시간 설정
통화와 숫자 설정
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.text.NumberFormat" %>
<%@page import="java.text.DateFormat"%>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>현재 로케일의 국가, 날짜, 통화</h3>
<%
Locale locale = request.getLocale();
Date currentDate = new Date();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
%>
<p> 국가 : <%=locale.getDisplayCountry() %></p>
<p> 날짜 : <%=dateFormat.format(currentDate) %></p>
<p> 숫자(12345.67) : <%=numberFormat.format(12345.67) %></p>
</body>
</html>
setLocale 태그
requestEncoding 태그 : 요청 파라미터의 문자 인코딩을 설정하는 태그
리소스 번들
리소스 번들로 사용하는 *.properties 파일의 종류
bundle 태그
message 태그
setBundle 태그
title =자바 서버 페이지
username =관리자
password =1234
title =Java Server Pages
username =admin
password =1234
<%@ 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 http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<fmt:requestEncoding value="UTF-8"/>
<p> ------------기본 로케일-----------------
<fmt:setBundle basename="ch09.com.bundle.myBundle" var="resourceBundle"/>
</p>
<p> 제목 : <fmt:message key="title" bundle="${resourceBundle}" /> </p>
<p> <fmt:message key="username" var="userMsg" bundle="${resourceBundle}" />이름 : ${userMsg}</p>
<p> ------------영문 로케일-----------------
<fmt:setLocale value="en"/>
<fmt:setBundle basename="ch09.com.bundle.myBundle" var="resourceBundle"/>
</p>
<p> 제목 : <fmt:message key="title" bundle="${resourceBundle}" /></p>
<p> 이름 : <fmt:message key="username" bundle="${resourceBundle}" /></p>
</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 http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p> 숫자 : <fmt:formatNumber value="3200100" /></p>
<p><fmt:formatNumber value="3200100" type="number" /></p>
<p><fmt:formatNumber value="3200100" type="number" groupingUsed="false" /></p>
<p><fmt:formatNumber value="3200100" type="currency" groupingUsed="true" /></p>
<p><fmt:formatNumber value="3200100" type="currency" currencySymbol="&" /></p>
<p><fmt:formatNumber value="0.45" type="percent"/></p>
<p><fmt:formatNumber value="3200100" minIntegerDigits="10" minFractionDigits="2" /></p>
<p><fmt:formatNumber value="3200100.45" pattern=".000"/></p>
<p><fmt:formatNumber value="3200100.456" pattern="#,#00.0#"/></p>
</body>
</html>
formatDate 태그
paseDate 태그
문자열로 표시된 날짜와 시간 값을 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" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p><jsp:useBean id="now" class="java.util.Date" /></p>
<p><fmt:formatDate value="${now}" type="time"/></p>
<p><fmt:formatDate value="${now}" type="both"/></p>
<p><fmt:formatDate value="${now}" type="both" dateStyle="default" timeStyle="default"/></p>
<p><fmt:formatDate value="${now}" type="both" dateStyle="short" timeStyle="short"/></p>
<p><fmt:formatDate value="${now}" type="both" dateStyle="medium" timeStyle="medium"/></p>
<p><fmt:formatDate value="${now}" type="both" dateStyle="long" timeStyle="long"/></p>
<p><fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/></p>
<p><fmt:formatDate value="${now}" type="both" pattern="yyyy년MM월dd일 HH시mm분ss초 E요일"/></p>
</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 http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="now" class="java.util.Date" />
<p>한국 : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/></p>
<p><fmt:timeZone value="America/New_York">
뉴욕 : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/>
</fmt:timeZone></p>
<p><fmt:timeZone value="Europe/London">
런던 : <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full"/>
</fmt:timeZone></p>
</body>
</html>
title = 상품 등록
ProductId = 상품 코드
pname = 상품명
unitPrice = 가격
description = 상세 설명
manufacturer = 제조사
category = 분류
unitsInStock = 재고 수
condition = 상태
productImage = 이미지
condition_New = 신규 제품
condition_Old = 중고 제품
condition_Refurbished = 재생 제품
button = 등록
title = Product Addition
ProductId = Product ID
pname = Name
unitPrice = Unit Price
description = Description
manufacturer = Manufacturer
category = Category
unitsInStock = Units in Stock
condition = Condition
productImage = Image
condition_New = New
condition_Old = Old
condition_Refurbished = Refurbished
button = Insert
<%@ 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 http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>상품 등록</title>
<style>
.inputRow {
margin: 15px 0px;
display: flex;
align-items : center;
}
.inputRow label {
width : 150px;
}
.inputRow input, .inputRow textarea {
font-size: 1.3rem;
}
.inputRow input.btn {
font-size: 1rem;
padding : 5px 15px;
}
</style>
<script type="text/javascript" src="./resources/js/validate.js">
</script>
</head>
<body>
<fmt:setLocale value="<%=request.getParameter("language") %>"/>
<fmt:bundle basename="bundle.message" >
<jsp:include page="header.jsp" />
<div class="main">
<div class="banner">
<div class="container">
<h1>상품 등록</h1>
</div>
</div>
<div class="content">
<div class="container">
<div class="text-right">
<a href="?language">Korean</a> | <a href="?language">English</a>
</div>
<form name="newProduct" action="./processAddProduct.jsp"
class="form-horizontal" method="post" enctype="multipart/form-data">
<div class="inputRow">
<label for="productId"><fmt:message key="productId" /> </label> <input type="text"
name="productId" id="productId">
</div>
<div class="inputRow">
<label for="name"><fmt:message key="pname" /></label> <input type="text" name="name" id ="name">
</div>
<div class="inputRow">
<label for="unitPrice"><fmt:message key="unitPrice" /></label> <input type="text" name="unitPrice" id="unitPrice">
</div>
<div class="inputRow">
<label for="description"><fmt:message key="description" /></label>
<textarea name="description" cols="50" rows="2" id="description">
</textarea>
</div>
<div class="inputRow">
<label for="manufacturer"><fmt:message key="manufacturer" /></label> <input type="text" name="manufacturer" id="manufacturer">
</div>
<div class="inputRow">
<label for="category"><fmt:message key="category" /></label> <input type="text" name="category" id="category">
</div>
<div class="inputRow">
<label for="unitStock"><fmt:message key="unitsInStock" /></label> <input type="text" name="unitInStock" id="unitStock">
</div>
<div class="inputRow">
<label><fmt:message key="condition" /></label>
<label><input type="radio" name="condition" value="New"> <fmt:message key="condition_New" /></label>
<label><input type="radio" name="condition" value="Old"> <fmt:message key="condition_Old" /></label>
<label><input type="radio" name="condition" value="Refurbished"> <fmt:message key="condition_Refurbished" /></label>
</div>
<div class="inputRow">
<label for="productImage"><fmt:message key="productImage" /></label>
<input type="file" name="productImage" id="productImage">
</div>
<div class="inputRow">
<input type="button" value="<fmt:message key="button" />" class="btn btn-secondary">
</div>
</form>
<hr>
</div>
</div>
</div>
</fmt:bundle>
<jsp:include page="footer.jsp" />
</body>
</html>