m1_product
list.jsp
생성<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="kr.product.dao.ProductDAO" %>
<%@ page import="kr.product.vo.ProductVO" %>
<%@ page import="kr.util.PagingUtil" %>
<%@ page import="java.util.List" %>
<%
String pageNum = request.getParameter("pageNum");
if(pageNum==null) pageNum = "1";
int currentPage = Integer.parseInt(pageNum);
ProductDAO dao = ProductDAO.getInstance();
int totalCount = dao.getCount();
int rowCount = 10;
int pageCount = 10;
String pageUrl = request.getRequestURI();
PagingUtil pg = new PagingUtil(currentPage, totalCount, rowCount, pageCount, pageUrl);
List<ProductVO> list = null;
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 목록</title>
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/layout.css">
</head>
<body>
<div class="page-main">
<h1>상품 목록</h1>
<div class="align-right">
<input type="button" value="상품 등록" onclick="location.href = 'writeForm.jsp';">
</div>
<%
if(totalCount<=0) {
%>
<div class="result-display">저장된 상품 정보가 없습니다!</div>
<%
}
else {
%>
<!-- 목록 출력 시작 -->
<table>
<tr>
<th>상품 번호</th>
<th>상품명</th>
<th>가격 (원)</th>
<th>재고 (개)</th>
<th>원산지</th>
<th>등록일</th>
</tr>
<%
list = dao.getList(pg.getStartCount(), pg.getEndCount());
for(ProductVO vo : list) {
%>
<tr>
<td><%= vo.getNum() %></td>
<td><a href="detail.jsp?num=<%= vo.getNum() %>"><%= vo.getName() %></a></td>
<td><%= String.format("%,d", vo.getPrice()) %></td>
<td><%= String.format("%,d", vo.getStock()) %></td>
<td><%= vo.getOrigin() %></td>
<td><%= vo.getReg_date() %></td>
</tr>
<%
}
%>
</table>
<!-- 목록 출력 끝 -->
<div class="align-center">
<%= pg.getPagingHtml() %>
</div>
<%
}
%>
</div>
</body>
</html>
detail.jsp
생성<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="kr.product.dao.ProductDAO" %>
<%@ page import="kr.product.vo.ProductVO" %>
<%
int num = Integer.parseInt(request.getParameter("num"));
ProductVO vo = ProductDAO.getInstance().getProduct(num);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 상세 정보</title>
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/layout.css">
<style type="text/css">
hr {color: gray; border-style: solid;}
</style>
</head>
<body>
<div class="page-main">
<h1>상품 상세 정보</h1>
<ul>
<li>
<label>상품 번호</label>
<%= vo.getNum() %>
</li>
<li>
<label>상품명</label>
<%= vo.getName() %>
</li>
<li>
<label>가격</label>
<%= String.format("%,d원", vo.getPrice()) %>
</li>
<li>
<label>재고</label>
<%= String.format("%,d개", vo.getStock()) %>
</li>
<li>
<label>원산지</label>
<%= vo.getOrigin() %>
</li>
<li>
<label>등록일</label>
<%= vo.getReg_date() %>
</li>
</ul>
<hr>
<p>
<%= vo.getContent() %>
</p>
<hr>
<div class="align-right">
<input type="button" value="수정" onclick="location.href = 'updateForm.jsp?num=<%= num %>';">
<input type="button" value="삭제" onclick="location.href = 'deleteForm.jsp?num=<%= num %>';">
<input type="button" value="목록" onclick="location.href = 'list.jsp';">
</div>
</div>
</body>
</html>
updateForm.jsp
생성<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="kr.product.dao.ProductDAO" %>
<%@ page import="kr.product.vo.ProductVO" %>
<%
int num = Integer.parseInt(request.getParameter("num"));
ProductVO vo = ProductDAO.getInstance().getProduct(num);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 정보 수정</title>
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/layout.css">
</head>
<body>
<div class="page-main">
<h1>상품 등록</h1>
<form action="update.jsp" method="post">
<input type="hidden" name="num" value="<%= num %>">
<ul>
<li>
<label for="name">상품명</label>
<input type="text" name="name" value="<%= vo.getName() %>">
</li>
<li>
<label for="price">가격</label>
<input type="number" name="price" value="<%= vo.getPrice() %>" min="0">
</li>
<li>
<label for="stock">재고</label>
<input type="number" name="stock" value="<%= vo.getStock() %>" min="0">
</li>
<li>
<label for="origin">원산지</label>
<input type="text" name="origin" value="<%= vo.getOrigin() %>">
</li>
<li>
<label for="content">상품 설명</label>
<textarea rows="5" cols="40" name="content"><%= vo.getContent() %></textarea>
</li>
</ul>
<div class="align-center">
<input type="submit" value="수정">
<input type="button" value="목록" onclick="location.href = 'list.jsp';">
</div>
</form>
</div>
<script type="text/javascript" src="<%= request.getContextPath() %>/js/validateLength.js"></script>
<script type="text/javascript">
document.querySelector('form').onsubmit = validateSubmit;
let txts = document.querySelectorAll('input[type="text"]');
for(let i=0;i<txts.length;i++) {
txts[i].onkeyup = function() {
while(getBytesLength(this.value)>30) {
this.value = this.value.slice(0, -1);
}
};
}
</script>
</body>
</html>
update.jsp
생성<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="kr.product.dao.ProductDAO" %>
<%
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean id="vo" class="kr.product.vo.ProductVO"></jsp:useBean>
<jsp:setProperty property="*" name="vo"/>
<%
ProductDAO.getInstance().update(vo);
%>
<script type="text/javascript">
alert('상품 정보를 수정하였습니다.');
location.href = 'list.jsp';
</script>
deleteForm.jsp
생성<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 정보 삭제</title>
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/layout.css">
</head>
<body>
<div class="page-main">
<h1>상품 정보 삭제</h1>
<form action="delete.jsp" method="post">
<input type="hidden" name="num" value="<%= request.getParameter("num") %>">
<div class="align-center">
정말 삭제하시겠습니까?<br>
<input type="submit" value="삭제">
<input type="button" value="목록" onclick="location.href = 'list.jsp'">
</div>
</form>
</div>
</body>
</html>
delete.jsp
생성<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="kr.product.dao.ProductDAO" %>
<%
ProductDAO.getInstance().delete(Integer.parseInt(request.getParameter("num")));
%>
<script type="text/javascript">
alert('상품 정보를 삭제하였습니다.');
location.href = 'list.jsp';
</script>