\

해병 코딩

728x90
반응형

 

 

 

 

 

 

 

 

 

jsp를 통해 간한 장바구니 웹을 만들어보았다 

 

<이번 프로잭트 흐름>

1. 로그인을 한다

 

 

2.원하는 상품을 고를수있다 (추가)

 

 

3.추가하는 상품이 저장된다.

4.저장된 상품 내역을 볼수있다

 

 

1_Longin.jsp 

코드

 

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page session="true"%>
<%
    request.setCharacterEncoding("UTF-8");// post 방식 한글깨짐 해결 코드 UTF-8로 다설정한다
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
<!-- 실행  로그인 화며-->
<title>로그인화면</title>
</head>
<body>
    <center>
        <h1>주류마을</h1>

        <hr>
        <form action="2_setProduct.jsp" method="post">
            <h3>로그인 화면</h3>
            <!-- required 입력 하지 않으면 넘어 가지 않는다 -->
            <input type="text" required name="name1"> <input
                type="submit" value="로그인" name="1_login">
        </form>
 
 
    </center>
</body>
</html>
 
cs
                                               

 

 

2_setProduct.jsp 

코드

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
    request.setCharacterEncoding("UTF-8");
%>
<!-- 로그인 할때의 아이디의  세션 만들기 -->
<!--  키 값 설정을 앞전 페이지에서 파라미터로 값을 가저온 내용을 적는다 request.getParameter("name1")      -->
<%
    session.setAttribute("NAME", request.getParameter("name1"));
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>주류 선택창</title>
</head>
 
<body>
    <center>
        <!-- 세션 받아오기   -->
        <%
            String name = (String) session.getAttribute("NAME"+ " 사장님의 멋있는 모습을 보고싶습니다";
        %>
        <%=name%>
        
        <br>
        <!-- select으로 선택 창을 만든다 -->
        <!-- form으로  -->
        <h1>주류 추가 하기</h1>
        <form action="3_add.jsp" method="post">
            <select name="productName">
 
                <option value="시원C1">시원C1</option>
                <option value="조니워커">조니워커</option>
                <option value="아르망디">아르망디</option>
                <option value="돔페르숑">돔페르숑</option>
                <option value="로얄샬룻">로얄샬룻</option>
            </select> <input type="submit" value="추가">
        </form>
        <!-- href 로 원하는 화면 으로 넘어간다 -->
        <a href="4_checkout.jsp"><%=name%>사장님 계산은여기서...</a>
        </center>
</body>
 
</html>
cs

 

3_add.jsp

코드

 

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
32
33
34
35
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
    request.setCharacterEncoding("UTF-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>저장 공간에 담아주기</title>
</head>
<form action="4_checkout.jsp">
 
    <body>
 
        <%
            String productName = request.getParameter("productName");// 세션 저장과 에레리 리스트공간에 저장 
            ArrayList<String> checkOutList = (ArrayList<String>) session.getAttribute("productList");
 
            if (checkOutList == null)
                checkOutList = new ArrayList<String>();
 
            checkOutList.add(productName);
            session.setAttribute("productList", checkOutList);// 위에 추가 하고  저장 해야 한다
        %>
        <!-- 추가 버튼 누를시 "주류가 추가 되었습니다"뜨게하고 확인 하면 다시 현재 화면으로 -->
        <script>
            alert("주류가 추가 되었습니다");
            history.back();
        </script>
</form>
 
</body>
</html>
cs

 

4_checkout.jsp 

코드

 

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
32
33
34
35
36
37
38
39
40
41
42
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
<%
    request.setCharacterEncoding("UTF-8");
%>
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>주문 목록</title>
</head>
<center>
    <body>
        <!-- 세션을로 지정한값을 불러온다 -->
        <%
            String name = (String) session.getAttribute("NAME"+ "  사장님";
        %>
 
        <%=name%>
        <h2>선택한 주류 목록</h2>
        <hr>
        <!--  porductList에 값이 없다면 업다는 말이 나오고 있다면 porductList 의 값을 보여주라 -->
        <%
            if (session.getAttribute("productList"== null)
                out.println(session.getAttribute("NAME"+ "  사장님이 선택한 주류이 없습니다");
            else
                out.println(session.getAttribute("productList"));
        %>
        <hr>
        <!-- 세션을 삭제 할수있는 코드가 있는데로 넘어 가는 코드 -->
        <!-- 이 코드를 만든이유 -->
        <form action="5delete.jsp">
            <input type="submit" value="로그아웃" name="longout"
                onclick="window.location.reload()"> <a
                href="javascript:history.back()">뒤로 가기</a>
        </form>
    </body>
</center>
 
</html>
cs

5delete.jsp

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>로그아웃 하는 코드</title>
</head>
<body>
    로그아웃 하셨습니다
    <%=request.getParameter("delete")%>
    <%
        session.invalidate();//종료 코드
    %>
    <script type="text/javascript">
        alert("로그아웃하시겠습니까");
        location.href = "1_Longin.jsp"//첫 번째 화면으로 돌아간다
    </script>
 
</body>
</html>
cs

 

 

 

 

 

 

※ 개발자  환경※

jdk1.8.0_162apache-tomcat-8.0.50깃허브

https://github.com/marine1188/-JSP-STUDY-file/tree/master/ShoppingBasket/WebContent

ShoppingBasket.zip
다운로드

위에 프로잭트 파일 다운 로드 하면 됨니다

 

 


저의 블로그 봐주셔서 감사합니다

재.미.있.게 보셧다면 아래 하트 ❤(공감) 과 댓글 부탁 드려요 .

다들 코로나 극복 화이팅 

728x90
반응형

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band