K 개발자

JSP BookMarket 만들기 - 8 본문

Web/JSP

JSP BookMarket 만들기 - 8

ddingz 2021. 8. 6. 18:10

이전 글
JSP BookMarket 만들기 - 1
JSP BookMarket 만들기 - 2
JSP BookMarket 만들기 - 3
JSP BookMarket 만들기 - 4
JSP BookMarket 만들기 - 5
JSP BookMarket 만들기 - 6
JSP BookMarket 만들기 - 7

실행 환경
자바 개발 환경 : jdk-15.0.2
웹 서버 환경 : Apache Tomcat v9.0
통합 개발 환경 : Eclipse IDE for Enterprise Java Developers

도서 등록 페이지의 다국어 처리하기

WebContent/WEB-INF/lib 폴더에 JSTL의 fmt 태그를 사용하기 위해 jstl-1.2.jar 파일을 등록한다.
src 폴더에 bundle 폴더를 생성하고 한글, 영문 리소스번들을 작성한다.

  • src 폴더에 bundle 폴더를 만든 후 여기에 message.properties, message_en.properties 파일을 생성하고 메시지를 작성한다.
# message.properties
title = \uB3C4\uC11C \uB4F1\uB85D
bookId = \uB3C4\uC11C\uCF54\uB4DC
name = \uB3C4\uC11C\uBA85
unitPrice = \uAC00\uACA9
author = \uC800\uC790
description = \uC0C1\uC138\uC815\uBCF4
publisher = \uCD9C\uD310\uC0AC
category = \uBD84\uB958
unitsInStock = \uC7AC\uACE0 \uC218
totalPages = \uCD1D\uD398\uC774\uC9C0 \uC218
releaseDate = \uCD9C\uD310\uC77C
condition = \uC0C1\uD0DC
bookImage = \uC774\uBBF8\uC9C0
condition_New = \uC2E0\uADDC \uB3C4\uC11C
condition_Old = \uC911\uACE0 \uB3C4\uC11C
condition_Refurbished = E-Book
button = \uB4F1\uB85D
# 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

WebContent 폴더의 addBook.jsp 파일에 다국어 처리를 작성한다.

<%-- 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-4"><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="newBook" 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-5">
						<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="EBook">
						<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" class="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>

웹 브라우저에 'http://localhost:8080/BookMarket/addBook.jsp'를 입력하고 한글 또는 영문을 선택한다.

다음 글
JSP BookMarket 만들기 - 9
JSP BookMarket 만들기 - 10
JSP BookMarket 만들기 - 11
JSP BookMarket 만들기 - 12
JSP BookMarket 만들기 - 13
JSP BookMarket 만들기 - 마지막

'Web > JSP' 카테고리의 다른 글

JSP BookMarket 만들기 - 10  (0) 2021.08.06
JSP BookMarket 만들기 - 9  (0) 2021.08.06
JSP BookMarket 만들기 - 7  (0) 2021.08.06
JSP BookMarket 만들기 - 6  (0) 2021.08.06
JSP BookMarket 만들기 - 5  (0) 2021.08.06
Comments