4. Locale 클래스를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.
locale.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.util.Locale" %>
<html>
<head>
<title>Internationalization</title>
</head>
<body>
<h3>현재 로케일</h3>
<%
Locale locale = request.getLocale();
String language = locale.getLanguage();
String country = locale.getCountry();
%>
<p> 언어 : <b><%=language %></b>
<p> 국가 : <b><%=country %></b>
</body>
</html>
5. JSTL fmt 태그를 이용하여 다음 조건에 맞게 JSP 애플리케이션을 만들고 실행 결과를 확인하시오.
jstl_fmt.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Internationalization</title>
</head>
<body>
<fmt:setLocale value='<%= request.getParameter("language") %>' />
<fmt:setBundle basename="ch09.com.bundle.myBundle" var="resourceBundle" />
<div class="text-left">
<a href="?language=ko" >Korean</a>|<a href="?language=en" >English</a>
</div>
<p><fmt:message key="id" bundle="${resourceBundle }"/> : <input type="text" name="id" />
<p><fmt:message key="password" bundle="${resourceBundle }"/> : <input type="text" name="password" />
<p><input type="submit" value="<fmt:message key="button" bundle="${resourceBundle }"/>">
</body>
</html>
myBundle.properties
id=아이디
password=비밀번호
button=전송
myBundle_en.properties
id=id
password=password
button=submit
6. 다음 조건에 맞게 도서 웹 쇼핑몰을 위한 웹 애플리케이션을 만들고 실행 결과를 확인하시오.
addBook.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<link rel = "stylesheet" href = "./resources/css/bootstrap.min.css" />
<script type="text/javascript" src="./resources/js/validation.js"></script>
<title>도서 등록</title>
</head>
<body>
<fmt:setLocale value='<%= request.getParameter("language") %>' />
<fmt:bundle basename="bundle.message" >
<jsp:include page="menu.jsp" />
<div class="jumbotron">
<div class="container">
<h1 class="display-3"><fmt:message key="title" /></h1>
</div>
</div>
<div class="container">
<div class="text-right">
<a href="?language=ko" >Korean</a>|<a href="?language=en" >English</a>
</div>
<form name="newProduct" action="./processAddBook.jsp" class="form-horizontal" method="post" enctype="multipart/form-data">
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="bookId" /></label>
<div class="col-sm-3">
<input type="text" id="bookId" name="bookId" class="form-control">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="name" /></label>
<div class="col-sm-3">
<input type="text" id="name" name="name" class="form-control">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="unitPrice" /></label>
<div class="col-sm-3">
<input type="text" id="unitPrice" name="unitPrice" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="author" /></label>
<div class="col-sm-3">
<input type="text" name="author" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="publisher" /></label>
<div class="col-sm-3">
<input type="text" name="publisher" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="releaseDate" /></label>
<div class="col-sm-3">
<input type="text" name="releaseDate" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="totalPages" /></label>
<div class="col-sm-3">
<input type="text" name="totalPages" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="description" /></label>
<div class="col-sm-7">
<textarea name="description" cols="50" rows="2" class="form-control" placeholder="100자 이상 적어주세요."></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="category" /></label>
<div class="col-sm-3">
<input type="text" name="category" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="unitsInStock" /></label>
<div class="col-sm-3">
<input type="text" id="unitsInStock" name="unitsInStock" class="form-control" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="condition" /></label>
<div class="col-sm-5">
<input type="radio" name="condition" value="NEW" >
<fmt:message key="condition_New" />
<input type="radio" name="condition" value="Old" >
<fmt:message key="condition_Old" />
<input type="radio" name="condition" value="E-Book" >
<fmt:message key="condition_Refurbished" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2"><fmt:message key="bookImage" /></label>
<div class="col-sm-5">
<input type="file" name="bookImage" value="form-control" >
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm-10">
<input type="button" class="btn btn-primary" value="<fmt:message key="button" />" onclick="CheckAddBook()">
</div>
</div>
</form>
</div>
</fmt:bundle>
</body>
</html>
message.properties
title = 도서 등록
bookId = 도서 아이디
name = 도서명
unitPrice = 가격
author = 저자
description = 상세 설명
publisher = 출판사
category = 분류
unitsInStock = 재고 수
totalPages = 총 페이지 수
releaseDate = 출판일
condition = 상태
bookImage = 이미지
condition_New = 신규 도서
condition_Old = 중고 도서
condition_Refurbished = E-book
button = 등록
message_en.properties
title = Book Addition
bookId = Book ID
name = Name
unitPrice = Unit Price
author = Author
description = Description
publisher = Publisher
category = Category
unitsInStock = Units in Stock
totalPages = TotalPages
releaseDate = ReleaseDate
condition = Condition
bookImage = Image
condition_New = New
condition_Old = Old
condition_Refurbished = E-book
button = Insert
'Problem solving > 쉽게 배우는 JSP 웹 프로그래밍' 카테고리의 다른 글
[쉽게 배우는 JSP 웹 프로그래밍] 11장 연습문제 (0) | 2021.01.03 |
---|---|
[쉽게 배우는 JSP 웹 프로그래밍] 10장 연습문제 (0) | 2020.11.04 |
[쉽게 배우는 JSP 웹 프로그래밍] 8장 연습문제 (0) | 2020.10.21 |
[쉽게 배우는 JSP 웹 프로그래밍] 7장 연습문제 (0) | 2020.10.21 |
[쉽게 배우는 JSP 웹 프로그래밍] 6장 연습문제 (0) | 2020.10.21 |