Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 추상메서드
- cursor문
- 컬렉션프레임워크
- 어윈 사용법
- Java
- 컬렉션 타입
- 다형성
- 객체 비교
- 사용자예외클래스생성
- 오라클
- 예외미루기
- 예외처리
- 참조형변수
- EnhancedFor
- 자동차수리시스템
- 메소드오버로딩
- abstract
- 환경설정
- exception
- 생성자오버로드
- 자바
- GRANT VIEW
- 한국건설관리시스템
- oracle
- 제네릭
- 대덕인재개발원
- 집합_SET
- 인터페이스
- 정수형타입
- NestedFor
Archives
- Today
- Total
거니의 velog
231110_JSP 개론 12 본문
* 예를 들면 채팅방의 읽기 처리, 세션 스토리지 등
[cookie01.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<form action="cookie01_process.jsp" method="post">
아이디 : <input type="text" name="id" /><br />
비밀번호 : <input type="text" name="pw" /><br />
<button type="submit">전송</button>
</form>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
[cookie01_process.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
if(id.equals("admin") && pw.equals("1234")){
Cookie cookie_id = new Cookie("userId", id);
Cookie cookie_pw = new Cookie("userPw", pw);
response.addCookie(cookie_id);
response.addCookie(cookie_pw);
out.println("쿠키 생성이 성공했습니다!<br />");
out.println(id + "님 환영합니다!<br />");
}else {
out.println("쿠키 생성이 실패했습니다!<br />");
}
%>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
- http://localhost/ch14/cookie01.jsp
[cookie02.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<%
Cookie[] cookies = request.getCookies();
out.println("현재 설정된 쿠키의 개수 : " + cookies.length + "<br />");
out.println("==============================================");
for(int i = 0; i < cookies.length; i++) {
out.println("설정된 쿠키의 속성 이름["+i+"] " + cookies[i].getName() + "<br />");
out.println("설정된 쿠키의 속성 값["+i+"] " + cookies[i].getValue() + "<br />");
out.println("==============================================");
}
%>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
- http://localhost/ch14/cookie02.jsp
[cookie03.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<%
Cookie[] cookies = request.getCookies();
for(int i = 0; i < cookies.length; i++){
cookies[i].setMaxAge(0); // 쿠키 삭제를 위해 기간을 0으로 설정
response.addCookie(cookies[i]);
}
response.sendRedirect("cookie02.jsp");
%>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
- http://localhost/ch14/cookie03.jsp
* 제이세션은 왜 남아 있는가? 브라우저가 켜질 때마다 다시 자동으로 생성되는 객체
[ch14_test.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<!--
아이디, 비밀번호를 process 페이지로 넘겨 인증처리를 진행해주세요.
이 때, 아이디저장 체크를 하고 로그인 성공 시 쿠키를 저장해 저장된 쿠키로 인해
다시 로그인 페이지를 reload 하면 아이디 저장이 체크되어 있고 아이디 입력란에
아이디가 입력된 상태에 로그인 페이지가 나타나게 해주세요.
아이디 저장 체크를 하지 않고 로그인 성공 시 쿠키를 저장하지 않고
다시 로그인 페이지를 reload했을 때 아이디 저장이 체크가 되어 있지 않은 상태로
페이지가 나타나게 해주세요.
> 아이디도 입력되어 있지 않게 해야겠죠?
-->
<%
Cookie[] cookies = request.getCookies();
String rememVal = "";
//out.println("==============================================<br />");
for(int i = 0; i < cookies.length; i++) {
//out.println("설정된 쿠키의 속성 이름["+i+"] " + cookies[i].getName() + "<br />");
//out.println("설정된 쿠키의 속성 값["+i+"] " + cookies[i].getValue() + "<br />");
//out.println("==============================================<br />");
if("userId".equals(cookies[i].getName())) {
rememVal = cookies[i].getValue();
}
}
//out.println("rememVal : " + rememVal);
%>
<script type="text/javascript">
$(function(){
var rememVal = "<%= rememVal %>";
//alert(rememVal);
$("input[name=id]").val(rememVal);
if(!rememVal) { // 쿠키 값이 없다는 말임
$("#rememberId").prop("checked", false);
}else { // 쿠키 값이 있다는 말임
$("#rememberId").prop("checked", true);
}
});
</script>
<form action="ch14_test_process.jsp" method="post">
아이디 : <input type="text" name="id" /><br />
비밀번호 : <input type="text" name="pw" /><br />
<input type="checkbox" id="rememberId" name="rememberId" />
<label for="rememberId">아이디 기억하기</label><br />
<button type="submit">로그인</button>
</form>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
[ch14_test_process.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<!--
넘겨받은 아이디와 비밀번호를 꺼낸 후,
임의로 설정한 아이디/비밀번호와 일치하는 경우에 "인증 성공했습니다!" 메시지를 출력하고
쿠키를 저장해 주세요.
일치하지 않는 정보인 경우, "인증 실패했습니다!" 메시지를 출력하고
다시 로그인 페이지로 이동할 수 있는 버튼을 제공해 주세요.
-->
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String remem = request.getParameter("rememberId");
//System.out.println("id : " + id);
//System.out.println("pw : " + pw);
//System.out.println("remem : " + remem);
if(remem != null) { // 아이디를 기억하겠다
//System.out.println("나를 기억해줘요~");
if(id.equals("admin") && pw.equals("1234")){ // 로그인 성공
Cookie cookie_id = new Cookie("userId", id);
response.addCookie(cookie_id);
out.println("인증 성공했습니다!<br />");
out.println("<a class='btn btn-primary' href='ch14_test.jsp'>로그인 페이지로 돌아가기</a>");
}else { // 로그인 실패
out.println("인증 실패했습니다!<br />");
out.println("<a class='btn btn-primary' href='ch14_test.jsp'>로그인 페이지로 돌아가기</a>");
}
}else {// 아이디를 기억하지 않겠다.
if(id.equals("admin") && pw.equals("1234")){
//System.out.println("나를 잊어줘요~");
Cookie[] cookies = request.getCookies();
for(int i = 0; i < cookies.length; i++){
cookies[i].setMaxAge(0); // 쿠키 삭제를 위해 기간을 0으로 설정
response.addCookie(cookies[i]);
}
out.println("인증 성공했습니다!<br />");
out.println("<a class='btn btn-primary' href='ch14_test.jsp'>로그인 페이지로 돌아가기</a>");
}else {
out.println("인증 실패했습니다!<br />");
out.println("<a class='btn btn-primary' href='ch14_test.jsp'>로그인 페이지로 돌아가기</a>");
}
}
%>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
- http://localhost/ch14/ch14_test.jsp
[선생님 풀이]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<!--
넘겨받은 아이디와 비밀번호를 꺼낸 후,
임의로 설정한 아이디/비밀번호와 일치하는 경우에 "인증 성공했습니다!" 메시지를 출력하고
쿠키를 저장해 주세요.
일치하지 않는 정보인 경우, "인증 실패했습니다!" 메시지를 출력하고
다시 로그인 페이지로 이동할 수 있는 버튼을 제공해 주세요.
-->
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String remem = request.getParameter("rememberId");
if(id.equals("admin") && pw.equals("1234")){ // 로그인 성공
out.println("인증 성공했습니다!<br />");
out.println("<a class='btn btn-primary' href='ch14_test.jsp'>로그인 페이지로 돌아가기</a>");
// 아이디 저장을 체크했는가?
Cookie cookie_id = null;
if(remem != null){ // 아이디 저장 체크 true
cookie_id = new Cookie("userId", id);
response.addCookie(cookie_id);
}else {
cookie_id = new Cookie("userId", id);
cookie_id.setMaxAge(0);
}
response.addCookie(cookie_id);
}else { // 로그인 실패
out.println("인증 실패했습니다!<br />");
out.println("<a class='btn btn-primary' href='ch14_test.jsp'>로그인 페이지로 돌아가기</a>");
}
%>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>쉽게 배우는 JSP 웹 프로그래밍</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<%@ include file="/pageModule/headPart.jsp" %>
</head>
<body>
<%@ include file="/pageModule/header.jsp" %>
<div class="breadcrumbs" style="padding-top:40px;">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-md-6 col-12">
<div class="breadcrumbs-content">
<h1 class="page-title">쿠키</h1>
</div>
</div>
<div class="col-lg-6 col-md-6 col-12">
<ul class="breadcrumb-nav">
<li><a href="/">INDEX</a></li>
<li>CH14</li>
</ul>
</div>
</div>
</div>
</div>
<section class="about-us section">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-lg-12 col-md-12 col-12">
<div class="content-left wow fadeInLeft" data-wow-delay=".3s">
<!--
아이디, 비밀번호를 process 페이지로 넘겨 인증처리를 진행해주세요.
이 때, 아이디저장 체크를 하고 로그인 성공 시 쿠키를 저장해 저장된 쿠키로 인해
다시 로그인 페이지를 reload 하면 아이디 저장이 체크되어 있고 아이디 입력란에
아이디가 입력된 상태에 로그인 페이지가 나타나게 해주세요.
아이디 저장 체크를 하지 않고 로그인 성공 시 쿠키를 저장하지 않고
다시 로그인 페이지를 reload했을 때 아이디 저장이 체크가 되어 있지 않은 상태로
페이지가 나타나게 해주세요.
> 아이디도 입력되어 있지 않게 해야겠죠?
-->
<%
boolean cookieFlag = false;
String id = "";
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for(int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if(cookie.getName().equals("userId")) {
id = cookie.getValue(); // 쿠키에 저장된 아이디를 저장
cookieFlag = true; // 아이디 저장 체크했구나?
}
}
}
%>
<form action="ch14_test_process.jsp" method="post">
아이디 : <input type="text" name="id" value="<%= id %>" /><br />
비밀번호 : <input type="text" name="pw" /><br />
<input type="checkbox" id="rememberId" name="rememberId" value="Y" <% if(cookieFlag){ %> checked <% } %> />
<label for="rememberId">아이디 기억하기</label><br />
<button type="submit">로그인</button>
</form>
</div>
</div>
</div>
</div>
</section>
<%@ include file="/pageModule/footer.jsp" %>
<%@ include file="/pageModule/footerPart.jsp" %>
</body>
</html>
[shoppingInfo.jsp]
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath }/resources/css/bootstrap.min.css" />
<title>배송 정보</title>
</head>
<body>
<%@ include file="menu.jsp" %>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">배송 정보</h1>
</div>
</div>
<div class="container">
<form action="processShoppingInfo.jsp" class="form-horizontal"method="post">
<input type="hidden" name="cartId" value="<%= request.getParameter("cartId") %>">
<div class="form-group row">
<label class="col-sm-2">성명</label>
<div class="col-sm-3">
<input name="name" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">배송일</label>
<div class="col-sm-3">
<input name="shoppingDate" type="text" class="form-control">(yyyy/mm/dd)
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">국가명</label>
<div class="col-sm-3">
<input name="country" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">우편번호</label>
<div class="col-sm-3">
<input name="zipCode" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">주소</label>
<div class="col-sm-5">
<input name="addressName" type="text" class="form-control">
</div>
</div>
<div class="form-group 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>
</body>
</html>
[processShoppingInfo.jsp]
<%@page import="java.net.URLEncoder"%>
<%@ page contentType="text/html; charset=utf-8"%>
<%
request.setCharacterEncoding("UTF-8");
Cookie cartId = new Cookie("Shopping_cartId", URLEncoder.encode(request.getParameter("cartId"), "UTF-8"));
Cookie name = new Cookie("Shopping_name", URLEncoder.encode(request.getParameter("name"), "UTF-8"));
Cookie shoppingDate = new Cookie("Shopping_shoppingDate", URLEncoder.encode(request.getParameter("shoppingDate"), "UTF-8"));
Cookie country = new Cookie("Shopping_country", URLEncoder.encode(request.getParameter("country"), "UTF-8"));
Cookie zipCode = new Cookie("Shopping_zipCode", URLEncoder.encode(request.getParameter("zipCode"), "UTF-8"));
Cookie addressName = new Cookie("Shopping_addressName", URLEncoder.encode(request.getParameter("addressName"), "UTF-8"));
cartId.setMaxAge(24 * 60 * 60); // 기간 : 하루
name.setMaxAge(24 * 60 * 60); // 기간 : 하루
shoppingDate.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(shoppingDate);
response.addCookie(country);
response.addCookie(zipCode);
response.addCookie(addressName);
response.sendRedirect("orderConfirmation.jsp"); // 영수증 페이지로 이동
%>
[orderConfirmation.jsp]
<%@page import="vo.Product"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.net.URLDecoder"%>
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<link rel="stylesheet" href="./resources/css/bootstrap.min.css" />
<title>주문 정보</title>
</head>
<body>
<%@ include file="menu.jsp" %>
<%
request.setCharacterEncoding("UTF-8");
String cartId = session.getId();
String shopping_cartId = "";
String shopping_name = "";
String shopping_shoppingDate = "";
String shopping_country = "";
String shopping_zipCode = "";
String shopping_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("Shopping_cartId")) {
shopping_cartId = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
if(n.equals("Shopping_name")) {
shopping_name = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
if(n.equals("Shopping_shoppingDate")) {
shopping_shoppingDate = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
if(n.equals("Shopping_country")) {
shopping_country = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
if(n.equals("Shopping_zipCode")) {
shopping_zipCode = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
if(n.equals("Shopping_addressName")) {
shopping_addressName = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
}
}
%>
<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>
<div class="row justify-content-between">
<div class="col-4" align="left">
<strong>배송 주소</strong> <br> 성명 : <% out.println(shopping_name); %><br>
우편번호 : <% out.println(shopping_zipCode); %><br>
주소 : <% out.println(shopping_addressName); %> <br>
</div>
<div class="col-4" align="right">
<p> <em>배송일: <% out.println(shopping_shoppingDate); %></em>
</div>
</div>
<div>
<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<Product> cartList = (ArrayList<Product>) session.getAttribute("cartList");
if(cartList == null) {
cartList = new ArrayList<Product>();
}
for(int i = 0; i < cartList.size(); i++){
Product product = cartList.get(i);
int total = product.getUnitPrice() * product.getQuantity();
sum = sum + total;
%>
<tr>
<td class="text-center"><em><%= product.getPname() %></em></td>
<td class="text-center"><%= product.getQuantity() %></td>
<td class="text-center"><%= product.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="./shoppingInfo.jsp?cartId=<%= shopping_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>
</body>
</html>
- http://localhost/shoppingInfo.jsp?cartId=BE723D5E665956AC878FFB0CD07B19DE
[thankCustomer.jsp]
<%@page import="java.net.URLDecoder"%>
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath }/resources/css/bootstrap.min.css" />
<title>주문 완료</title>
</head>
<body>
<%@ include file="menu.jsp" %>
<%
String shopping_cartId = "";
String shopping_shoppingDate = "";
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("Shopping_cartId")) {
shopping_cartId = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
if(n.equals("Shopping_shoppingDate")) {
shopping_shoppingDate = URLDecoder.decode(thisCookie.getValue(), "UTF-8");
}
}
}
%>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">주문 완료</h1>
</div>
</div>
<div class="container">
<h2 class="alert alert-danger">주문해주셔서 감사합니다.</h2>
<p>주문은 <%= shopping_shoppingDate %>에 배송될 예정입니다! !
<p>주문번호 : <%= shopping_cartId %>
</div>
<div class="container">
<p><a href="./products.jsp" class="btn btn-secondary"> « 상품 목록</a>
</div>
</body>
<%
// 세션에 등록된 카트 목록을 삭제
session.invalidate();
// 쿠키에 등록된 주문정보 데이터를 삭제
for(int i = 0; i < cookies.length; i++){
Cookie thisCookie = cookies[i];
String n = thisCookie.getName();
if(n.equals("Shopping_cartId")){
thisCookie.setMaxAge(0);
}
if(n.equals("Shopping_name")){
thisCookie.setMaxAge(0);
}
if(n.equals("Shopping_shoppingDate")){
thisCookie.setMaxAge(0);
}
if(n.equals("Shopping_country")){
thisCookie.setMaxAge(0);
}
if(n.equals("Shopping_zipCode")){
thisCookie.setMaxAge(0);
}
if(n.equals("Shopping_addressName")){
thisCookie.setMaxAge(0);
}
response.addCookie(thisCookie);
}
%>
</html>
- http://localhost/thankCustomer.jsp
[checkOutCancelled.jsp]
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<link rel="stylesheet" href="./resources/css/bootstrap.min.css" />
<title>주문 취소</title>
</head>
<body>
<%@ include file="menu.jsp" %>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">주문 취소</h1>
</div>
</div>
<div class="container">
<h2 class="alert alert-danger">주문이 취소되었습니다.</h2>
</div>
<div class="container">
<p><a href="./products.jsp" class="btn btn-secondary"> « 상품 목록</a>
</div>
</body>
</html>
'대덕인재개발원 > 대덕인재개발원_웹기반 애플리케이션' 카테고리의 다른 글
231114_JSP 개론 14 (1) | 2023.11.14 |
---|---|
231113_JSP 개론 13 (0) | 2023.11.13 |
231109_CRUD 과제 (1) | 2023.11.09 |
231109_JSP 개론 11 (0) | 2023.11.09 |
231108_JSP 개론 10 (0) | 2023.11.08 |