본문 바로가기
JSP/웹페이지 만들기

JSP 20230629 웹페이지 만들기 5장 실습

by 미눅스[멘토] 2023. 6. 29.
728x90

 

products.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="bookVO.BookVO"%>
<%@ page import="java.util.List"%>
<%@ page import="bookDAO.BookReposutory"%>

<%
BookReposutory bookDAO = BookReposutory.getInstance(); 
List<BookVO> books = bookDAO.getAllProducts();
%>
<c:set var="books" value="<%=books%>"></c:set>
  
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<link rel="stylesheet"
   href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> 
  
   
  
<body>
<%@ include file="menu.jsp" %>
	<div class="jumbotron">
		<div class="container">
			<h1 class="display-3">
				도서 목록
			</h1>
		</div>
	</div>
	<div style="width: 60%; margin: 0px auto;">
		<c:forEach var="book" items="${books}" varStatus="stat">
			<table style="margin: 0px auto; width: 100%;">
				<tr>
					<th><h3>[${book.category}] ${book.name}</h3></th>
				</tr>
				<tr>
					<td>${book.description}<br><br></td>
					<td rowspan="2" style="position: relative;"><a style="position: absolute; top: 0px;" href="product.jsp?id=${book.bookId}" class="btn btn-secondary">상세 정보&raquo;</a></td>
				</tr>
				<tr>
					<td>${book.author} | ${book.publisher} | ${book.unitPrice}<br></td>
				</tr>
			</table>
			<hr>
		</c:forEach>		
	</div>
	<footer class="container">
		<p>&copy;BookMarket</p>	
	</footer>

</body>
</html>

결과

 

 

product

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="bookVO.BookVO"%>
<%@ page import="java.util.List"%>
<%@ page import="bookDAO.BookReposutory"%>

<%
BookReposutory bookDAO = BookReposutory.getInstance(); 
String id = request.getParameter("id");
BookVO book = bookDAO.getBookById(id);
%>





<c:set var="book" value="<%=book%>"></c:set>
  
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<link rel="stylesheet"
   href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> 
  
   
  
<body>
<%@ include file="menu.jsp" %>
	<div class="jumbotron">
		<div class="container">
			<h1 class="display-3">
				도서 정보
			</h1>
		</div>
	</div>
	<div style="width: 60%; margin: 0px auto;">
			<table style="margin: 0px auto; width: 100%;">
				<tr>
					<th><h3>[${book.category}] ${book.name}</h3></th>
				</tr>
				<tr>
					<td>${book.description}</td>
				</tr>
				<tr>
					<td>도서코드 : <span class="badge badge-danger">${book.bookId}</span></td>
				</tr>
				<tr>
					<td>출판사 : ${book.publisher}</td>
				</tr>
				<tr>
					<td>저자 : ${book.author}</td>
				</tr>
				<tr>
					<td>재고수 : ${book.unitsInStock}</td>
				</tr>
				<tr>
					<td>총 페이지 수 : ${book.totalPages}</td>
				</tr>
				<tr>
					<td>출판일 : ${book.releseDate}</td>
				</tr>
				<tr>
					<td><h3>${book.unitPrice}</h3></td>
				</tr>
				<tr>
					<td>
						<a href="#" class="btn btn-secondary">도서주문&raquo;</a>
						<a href="/products.jsp" class="btn btn-danger">도서목록&raquo;</a>
					</td>
				</tr>
			</table>
			<hr>
	</div>
	<footer class="container">
		<p>&copy;BookMarket</p>	
	</footer>

</body>
</html>