구현
구현2 - 상세보기 구현
구현3 - 상품 추가
구현4 - 이미지 추가
구현5 - 유효성검사 / 다국어
구현6 - 시큐리티
구현7 - 예외 처리
구현8 - 로그
구현 9 - 장바구니(세션)
shippingInfo.jsp
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body>
<!-- header -->
<%@ include file="menu.jsp" %>
<!-- 표현문 -->
<div class="jumbotron">
<div class="container">
<h1 class="display-3">배송 정보</h1>
</div>
</div>
<!-- --------------------배송 정보 시작-------------------- -->
<!-- /shippingInfo.jsp?cartId=FC168E8DF4B5079F18B719D89DA0075B -->
<div class="container">
<!--
요청URI : /processShippingInfo.jsp
요청파라미터 : {name=개똥이,shippingDate=2024-07-18,
country=대한민국,zipCode=12345,addressName=중구 선화동123}
요청방식 : post
-->
<form action="/processShippingInfo.jsp" class="form-horizontal" method="post">
<input type="text" name="cartId" value="<%=request.getParameter("cartId") %>"/>
<div class="form-group row">
<label class="col-sm-2">성명</label>
<div class="col-sm-3">
<input type="text" name="name" class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">배송일</label>
<div class="col-sm-3">
<input type="date" name="shippingDate" class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">국가명</label>
<div class="col-sm-3">
<input type="text" name="country" class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">주소</label>
<div class="col-sm-3">
<input type="text" name="addressName" class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">우편번호</label>
<div class="col-sm-3">
<input type="text" name="zipCode" class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-offset-2 col-sm-10">
<a href="/cart.jsp?cartId=<%=request.getAttribute("cartId")%>" role="button" class="btn btn-secondary">이전</a>
<input type="submit" class="btn btn-primary" value="등록"/>
<a href="/checkOutCancelled.jsp" class="btn btn-secondary" role="button">취소</a>
</label>
</div>
</form>
</div>
<!-- footer -->
<%@ include file="footer.jsp" %>
</body>
</html>
processShippingInfo.jsp
<%@page import="java.net.URLEncoder"%>
<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
Enumeration en = request.getParameterNames();
Cookie[] cookies = new Cookie[6];
int cnt = 0;
while(en.hasMoreElements()){
String paramName = (String)en.nextElement();
out.println(paramName);
/*
//paramName : [cartId, name, shippingDate
// , country, zipCode, addressName]
request{cartId=aslkasdfj,name=개똥이,shippingDate=2024-07-18,
country=대한민국,zipCode=12345,addressName=중구 선화동123}
*/
//cookies
//[0] [1] [2] [3] [4] [5]
//cartId쿠키 name쿠키 ..
cookies[cnt] = new Cookie("Shipping_"+paramName,
URLEncoder.encode(request.getParameter(paramName),"UTF-8"));
cookies[cnt].setMaxAge(60*60);
response.addCookie(cookies[cnt++]);
}
response.sendRedirect("/orderConfirmation.jsp");
%>
<a href="/ch14/cookies01.jsp" target="_blank">[테스트] 쿠키생성 확인</a>
orderConfirmation.jsp
<%@page import="java.net.URLDecoder"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String Shipping_name = "";
String Shipping_zipCode = "";
String Shipping_country = "";
String Shipping_addressName = "";
String Shipping_shippingDate = "";
String Shipping_cartId = "";
Cookie[] cookies = request.getCookies();
//쿠키의 개수만큼 반복
for(int i=0;i<cookies.length;i++){
Cookie thisCookie = cookies[i];
//쿠키 이름 가져옴
// out.print(thisCookie.getName() + "<br />");
//쿠키 값 가져옴
// out.print(URLDecoder.decode(thisCookie.getValue(),"UTF-8")+"<br />");
if(thisCookie.getName().equals("Shipping_name")){
Shipping_name = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_zipCode")){
Shipping_zipCode = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_country")){
Shipping_country = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_addressName")){
Shipping_addressName = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_shippingDate")){
Shipping_shippingDate = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_cartId")){
Shipping_cartId = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
}
%>
<!-- header -->
<%@ include file="menu.jsp" %>
<!-- 표현문 -->
<div class="jumbotron">
<div class="container">
<h1 class="display-3">주문 정보</h1>
</div>
</div>
<div class="container col-8 alert alert-info">
<div class="text-center">
<h1>영수증</h1>
</div>
<!-- 고객 정보 시작 : cookie 사용 -->
<div class="row justify-content-between">
<strong>배송 주소</strong><br>
성명 : <%=Shipping_name %><br>
우편번호 : <%=Shipping_zipCode %><br>
주소 : <%=Shipping_addressName %> <%=Shipping_country %><br>
</div>
<div class="col-4" align="right">
<p>
<em>배송일 : <%=Shipping_shippingDate %></em>
</p>
</div>
</div>
<!-- footer -->
<%@ include file="footer.jsp" %>
</body>
</html>
thankCustomer.jsp
<%@page import="kr.or.ddit.vo.ProductVO"%>
<%@page import="java.util.List"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String Shipping_name = "";
String Shipping_zipCode = "";
String Shipping_country = "";
String Shipping_addressName = "";
String Shipping_shippingDate = "";
String Shipping_cartId = "";
Cookie[] cookies = request.getCookies();
//쿠키의 개수만큼 반복
for(int i=0;i<cookies.length;i++){
Cookie thisCookie = cookies[i];
//쿠키 이름 가져옴
// out.print(thisCookie.getName() + "<br />");
//쿠키 값 가져옴
// out.print(URLDecoder.decode(thisCookie.getValue(),"UTF-8")+"<br />");
if(thisCookie.getName().equals("Shipping_name")){
Shipping_name = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_zipCode")){
Shipping_zipCode = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_country")){
Shipping_country = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_addressName")){
Shipping_addressName = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_shippingDate")){
Shipping_shippingDate = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
if(thisCookie.getName().equals("Shipping_cartId")){
Shipping_cartId = URLDecoder.decode(thisCookie.getValue(),"UTF-8");
}
}
//장바구니 세션 가져오기
List<ProductVO> list = (List<ProductVO>)session.getAttribute("cartlist");
%>
<!-- header -->
<%@ include file="menu.jsp" %>
<!-- 표현문 -->
<div class="jumbotron">
<div class="container">
<h1 class="display-3">주문 완료</h1>
</div>
</div>
<div class="container">
<h2 class="alert alert-success" style="color:green;font-weight:bold;">주문해주셔서 감사합니다.</h2>
<p>주문은 <%=Shipping_shippingDate %>에 배송될 예정입니다.</p>
<p>주문 번호 : <%=Shipping_cartId %></p>
</div>
<div class="container">
<p>
<a href="/products.jsp"
class="btn btn-secondary">«상품 목록</a>
</p>
</div>
<!-- footer -->
<%@ include file="footer.jsp" %>
<%
// 장바구니 비우기
session.removeAttribute("cartlist");
// 배송정보 쿠키 삭제
for(Cookie cookie : cookies){
cookie.setMaxAge(0);
response.addCookie(cookie);
}
%>
</body>
</html>
checkOutCancelled.jsp
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body>
<!-- header -->
<%@ include file="menu.jsp" %>
<!-- 표현문 -->
<div class="jumbotron">
<div class="container">
<h1 class="display-3">주문 취소</h1>
</div>
</div>
<div class="container">
<%
session.removeAttribute("cartlist");
Cookie[] cookies = request.getCookies();
// 배송정보 쿠키 삭제
for(Cookie cookie : cookies){
cookie.setMaxAge(0);
response.addCookie(cookie);
}
%>
<h2 class="alert alert-danger" style="color:red;font-weight:bold;">주문이 취소되었습니다.</h2>
</div>
<div class="container">
<p>
<a href="/products.jsp" class="btn btn-secondary" role="button">상품 목록 »</a>
</p>
</div>
<!-- footer -->
<%@ include file="footer.jsp" %>
</body>
</html>