JSP/BookMarket

주문 처리 페이지 만들기

별초롱언니 2025. 6. 2. 16:56
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://kit.fontawesome.com/705381df09.js" crossorigin="anonymous"></script>
<title>배송 정보</title>
</head>
<body>
<div class="container py-4">
	<%@ include file="menu.jsp" %>
	
	<div class="p-5 mb-4 bg-body-tertiary rounded-3">
		<div class="container-fluid py-5">
			<h1 class="display-5 fw-bold">배송 정보</h1>
			<p class="col-md-8 fs-4">Shipping Info</p>
		</div>
	</div>
	
	<div class="row align-items-md-stretch">
		<form action="./processShippingInfo.jsp" method="post">
			<input type="hidden" name="cartId" value=<%= request.getParameter("cartId") %>>
			
			<div class="mb-3 row">
				<label class="col-sm-2">성명</label>
				<div class="col-sm-3">
					<input type="text" name="name" class="form-control">
				</div>
			</div>
			
			<div class="mb-3 row">
				<label class="col-sm-2">배송일</label>
				<div class="col-sm-3">
					<input type="text" name="shippingDate" class="form-control" placeholder="(yyyy/mm/dd)">
				</div>
			</div>
			
			<div class="mb-3 row">
				<label class="col-sm-2">국가명</label>
				<div class="col-sm-3">
					<input type="text" name="country" class="form-control">
				</div>
			</div>
			
			<div class="mb-3 row">
				<label class="col-sm-2">우편번호</label>
				<div class="col-sm-3">
					<input type="text" name="zipCode" class="form-control">
				</div>
			</div>
			
			<div class="mb-3 row">
				<label class="col-sm-2">주소</label>
				<div class="col-sm-5">
					<input type="text" name="addressName" class="form-control">
				</div>
			</div>
			
			<div class="mb-3 row">
				<div class="col-sm-offset-2 col-sm-10">
					<a href="./cart.jsp?cartId=<%=request.getParameter("cartId")%>" class="btn btn-secondary" role="button"> 이전 </a>
					<input type="submit" class="btn btn-primary" value="등록" />
					<a href="./checkOutCancelled.jsp" class="btn btn-secondary" role="button"> 취소 </a>
				</div>
			</div>
			
		</form>
	</div>
	
	<jsp:include page="footer.jsp"/>	
</div>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.net.URLEncoder" %>
<%System.out.println("processShippingInfo입장"); %>
<% 
	request.setCharacterEncoding("UTF-8");

	Cookie cartId = new Cookie("Shipping_cartId",URLEncoder.encode(request.getParameter("cartId"), "utf-8"));
	Cookie name = new Cookie("Shipping_name",URLEncoder.encode(request.getParameter("name"), "utf-8"));
	Cookie shippingDate = new Cookie("Shipping_shippingDate",URLEncoder.encode(request.getParameter("shippingDate"), "utf-8"));
	Cookie country = new Cookie("Shipping_country",URLEncoder.encode(request.getParameter("country"), "utf-8"));
	Cookie zipCode = new Cookie("Shipping_zipCode",URLEncoder.encode(request.getParameter("zipCode"), "utf-8"));
	Cookie addressName = new Cookie("Shipping_addressName",URLEncoder.encode(request.getParameter("addressName"), "utf-8"));
	
	// 하루(24시간 = 86400초) 동안 쿠키를 유지
	cartId.setMaxAge(24 * 60 * 60);
	name.setMaxAge(24 * 60 * 60);
	shippingDate.setMaxAge(24 * 60 * 60);
	country.setMaxAge(24 * 60 * 60);
	zipCode.setMaxAge(24 * 60 * 60);
	addressName.setMaxAge(24 * 60 * 60);
	
	response.addCookie(cartId);
	response.addCookie(name);
	response.addCookie(shippingDate);
	response.addCookie(country);
	response.addCookie(zipCode);
	response.addCookie(addressName);
	
	response.sendRedirect("orderConfirmation.jsp");
%>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="dto.Book" %>
<%@ page import="dao.BookRepository" %>
<%System.out.println("orderConfirmation 입장"); %>

<%
	request.setCharacterEncoding("UTF-8");

	String cartId = session.getId();
	
	String shipping_cartId = "";
	String shipping_name = "";
	String shipping_shippingDate = "";
	String shipping_country = "";
	String shipping_zipCode = "";
	String shipping_addressName = "";
	
	Cookie[] cookies = request.getCookies();
	
	if (cookies != null) {
		for (int i=0; i<cookies.length; i++) {
			Cookie thisCookie = cookies[i];
			String n = thisCookie.getName();
			if (n.equals("Shipping_cartId")) { shipping_cartId = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_name")) { shipping_name = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_shippingDate")) { shipping_shippingDate = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_country")) { shipping_country = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_zipCode")) { shipping_zipCode = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_addressName")) { shipping_addressName = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
		}
	}
%>
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://kit.fontawesome.com/705381df09.js" crossorigin="anonymous"></script>
<title>주문 정보</title>
</head>
<body>
<div class="container py-4">
	<%@ include file="menu.jsp" %>
	
	<div class="p-5 mb-4 bg-body-tertiary rounded-3">
		<div class="container-fluid py-5">
			<h1 class="display-5 fw-bold">주문 정보</h1>
			<p class="col-md-8 fs-4">Order Info</p>
		</div>
	</div>
	
	<div class="row align-items-md-stretch alert alert-info">
		<div class="text-center">
			<h1>영수증</h1>
		</div>
		
		<div class="row justify-content-between">
			<div class="col-4" align="left">
				<strong>배송 주소</strong> <br> 성명 : <% out.println(shipping_name); %><br>
				우편번호 : <% out.println(shipping_zipCode); %><br>
				주소 : <% out.println(shipping_addressName); %>(<% out.println(shipping_country);%>)<br>
			</div>
			
			<div class="col-4" align="right">
				<p><em>배송일 : <% out.println(shipping_shippingDate); %></em>
			</div>
		</div>
		
		<div class="py-5">
			<table class="table table-hover">
				<tr>
					<th class="text-center">도서</th>
					<th class="text-center">#</th>
					<th class="text-center">가격</th>
					<th class="text-center">소계</th>
				</tr>
				
				<%
					int sum = 0;
					ArrayList<Book> cartList = (ArrayList<Book>) session.getAttribute("cartlist");
					
					if (cartList == null) {
						cartList = new ArrayList<Book>();
					}
					for (int i=0; i<cartList.size(); i++) {
						Book book = cartList.get(i);
						int total = book.getUnitPrice() * book.getQuantity();
						sum += total;
				%>
				
				<tr>
					<td class="text-center"><em><%=book.getName() %></em></td>
					<td class="text-center"><%=book.getQuantity() %></td>
					<td class="text-center"><%=book.getUnitPrice() %>원</td>
					<td class="text-center"><%=total %>원</td>
				</tr>
				<%
					}
				%>
				<tr>
					<td> </td>
					<td> </td>
					<td class="text-right"><strong>총액 : </strong></td>
					<td class="text-center text-danger"><strong><%=sum %></strong></td>
				</tr>
			</table>
			
			<a href="./ShippingInfo.jsp?cartId=<%= shipping_cartId %>" class="btn btn-secondary" role="button"> 이전 </a>
			<a href="./thankCustomer.jsp" class="btn btn-success" role="button"> 주문 완료 </a>
			<a href="./checkOutCancelled.jsp" class="btn btn-secondary" role="button"> 취소 </a>
		</div>
	</div>
	
</div>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.net.URLDecoder" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://kit.fontawesome.com/705381df09.js" crossorigin="anonymous"></script>
<title>주문 완료</title>
</head>
<body>
<%
	String shipping_cartId = "";
	String shipping_name = "";
	String shipping_shippingDate = "";
	String shipping_country = "";
	String shipping_zipCode = "";
	String shipping_addressName = "";
	
	Cookie[] cookies = request.getCookies();
	
	if (cookies != null) {
		for (int i=0; i<cookies.length; i++) {
			Cookie thisCookie = cookies[i];
			String n = thisCookie.getName();
			if (n.equals("Shipping_cartId")) { shipping_cartId = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_name")) { shipping_name = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_shippingDate")) { shipping_shippingDate = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_country")) { shipping_country = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_zipCode")) { shipping_zipCode = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
			if (n.equals("Shipping_addressName")) { shipping_addressName = URLDecoder.decode((thisCookie.getValue()), "utf-8"); }
		}
	}
%>

<div class="container py-4">
	<%@ include file="menu.jsp" %>
	
	<div class="p-5 mb-4 bg-body-tertiary rounded-3">
		<div class="container-fluid py-5">
			<h1 class="display-5 fw-bold">주문 완료</h1>
			<p class="col-md-8 fs-4">Order Completed</p>
		</div>
	</div>
	
	<div class="row align-items-md-stretch">
		<h2 class="alert alert-danger">주문해주셔서 감사합니다.</h2>
		<p> 주문은 <% out.println(shipping_shippingDate); %>에 배송될 예정입니다!
		<p> 주문번호 : <% out.println(shipping_cartId); %>
	</div>
	<div class="container">
		<p><a href="./books.jsp" class="btn btn-secondary">&laquo; 도서 목록</a>
	</div>
	<%@ include file="footer.jsp" %>
</div>
</body>
</html>

<%
	session.invalidate();

	for (int i=0; i<cookies.length; i++) {
		Cookie thisCookie = cookies[i];
		String n = thisCookie.getName();
		if (n.equals("Shipping_cartId")) { thisCookie.setMaxAge(0); }
		if (n.equals("Shipping_name")) { thisCookie.setMaxAge(0); }
		if (n.equals("Shipping_shippingDate")) { thisCookie.setMaxAge(0); }
		if (n.equals("Shipping_country")) { thisCookie.setMaxAge(0); }
		if (n.equals("Shipping_zipCode")) { thisCookie.setMaxAge(0); }
		if (n.equals("Shipping_addressName")) { thisCookie.setMaxAge(0); }
		
		response.addCookie(thisCookie);
	}
%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://kit.fontawesome.com/705381df09.js" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
<title>주문 취소</title>
</head>
<body>
<div class="container py-4">
	<%@ include file="menu.jsp" %>
	
	<div class="p-5 mb-4 bg-body-tertiary rounded-3">
		<div class="container-fluid py-5">
			<h1 class="display-5 fw-bold">주문 취소</h1>
			<p class="col-md-8 fs-4">Order Cancellation</p>
		</div>
	</div>
	
	<div class="row align-items-md-stretch">
		<h2 class="alert alert-danger">주문이 취소되었습니다.</h2>
	</div>
	<div class="container">
		<p><a href="./books.jsp" class="btn btn-secondary">&laquo; 도서 목록</a>
	</div>
	<%@ include file="footer.jsp" %>
</div>
</body>
</html>