본문 바로가기
study/Spring

[Spring] 24. Spring (상품등록 [edit])

by 금이패런츠 2022. 5. 4.
728x90
반응형

edit.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%-- /springmvc1/src/main/webapp/WEB-INF/view/item/edit.jsp --%>  
<%--
	1. 유효성 검증
	2. 파일 업로드
 --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 등록</title>
<%-- 
	modelAttribute="item" : Controller에서 반드시 Item 객체 요구 
	<form:form : form 태그. 유효성 검증을 위한 form 태그
	enctype="multipart/form-data" : 파일 업로드. method="POST" 자동 설정
--%>
</head>
<body>
	<form:form modelAttribute="item" action="register" enctype="multipart/form-data">
		<h2>상품 등록</h2>
			<table>
				<tr>
					<td>상품명</td>
					<%-- 
						form:input : input 태그
						path 속성 : name='name' id='name' 속성을 자동으로 설정.
								   value="${item.name}"
						<form:errors path="name" /> : 오류 발생시 name 프로퍼티의 메세지를 출력.
					--%>
					<td><form:input path="name" maxlength="20" /></td>
					<td><font color="red"><form:errors path="name" /></font></td>
				</tr>
				<tr>
					<td>상품가격</td>
					<td><form:input path="price" maxlength="20" /></td>
					<td><font color="red"><form:errors path="price" /></font></td>
				</tr>
				<tr>
					<td>상품이미지</td>
					<td colspan="2"><input type="file" name="picture"></td>
				</tr>
				<tr>
					<td>상품설명</td>
					<td><form:textarea path="description" cols="20" rows="5" /></td>
					<td><font color="red"><form:errors path="description" /></font></td>
				</tr>
				<tr>
					<td colspan="3"><input type="submit" value="상품등록">&nbsp;
						<input type="button" value="상품목록" onclick="location.href='list'">
					</td>
				</tr>
			</table>
	</form:form>
</body>
</html>
728x90
반응형