3. 메시지 리소스 파일에 설정된 메시지를 도서 등록 페이지의 폼 필드 이름에 출력하려면 뷰 페이지 addBook.jsp 파일의 <spring:message> 태그를 수정·작성해야 합니다.
코드 12-4 addBook.jsp
<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> ➊
<html>
<head>
<link href="<c:url value="/resources/css/bootstrap.min.css"/>" rel="stylesheet">
<title>도서 등록</title>
</head>
<body>
<nav class="navbar navbar-expand navbar-dark bg-dark">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="./home">Home</a>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">
<spring:message code="addBook.form.title.label"/> ➋
</h1>
</div>
</div>
<div class="container">
<div class="float-right">
<form:form action="${pageContext.request.contextPath}/logout" method="POST">
<input type="submit" class="btn btn-success" value="Logout"/>
</form:form>
</div>
<form:form modelAttribute="NewBook"
action="./add?${_csrf.parameterName}=${_csrf.token}"
class="form-horizontal"
enctype="multipart/form-data">
<fieldset>
<legend><spring:message code="addBook.form.subtitle.label"/></legend> ➋
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.bookId.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="bookId" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label" >
<spring:message code="addBook.form.name.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="name" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label" >
<spring:message code="addBook.form.unitPrice.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="unitPrice" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label" >
<spring:message code="addBook.form.author.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="author" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.description.label"/> ➋
</label>
<div class="col-sm-5">
<form:textarea path="description" cols="50" rows="2"
class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.publisher.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="publisher" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.category.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="category" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.unitsInStock.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="unitsInStock" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.releaseDate.label"/> ➋
</label>
<div class="col-sm-3">
<form:input path="releaseDate" class="form-control"/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.condition.label"/> ➋
</label>
<div class="col-sm-3">
<form:radiobutton path="condition" value="New"/>New
<form:radiobutton path="condition" value="Old"/>Old
<form:radiobutton path="condition" value="E-Book"/>E-Book
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 control-label">
<spring:message code="addBook.form.bookImage.label"/> ➋
</label>
<div class="col-sm-7">
<form:input path="bookImage" type="file" class="form-control"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary"
value ="<spring:message code="addBook.form.button.label"/> "/> ➋
</div>
</div>
</fieldset>
</form:form>
<hr>
<footer>
<p>© BookMarket</p>
</footer>
</div>
</body>
</html>
➊ <spring:message> 태그를 사용하려고 스프링 태그 라이브러리를 선언합니다.
➋ <spring:message> 태그로 메시지 리소스 파일 messages.properties에서 폼 필드에 해당하는 값의 메시지를 읽어 와 출력합니다.