jsp 회원등록,수정,삭제,리스트(CRUD) 로직 구현하기 구매 아이템
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
package controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import damain.ItemVo;
import service.ItemDao;
@WebServlet("/itemController")
public class itemController extends HttpServlet {
protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
String uri = request.getRequestURI();
System.out.println("uri:"+uri);
String pj = request.getContextPath();
System.out.println(pj);
String command = uri.substring(pj.length());
System.out.println("command:"+command);
if(command.equals("/item/itemA.do")) {
System.out.println("왓음");
RequestDispatcher rd = request.getRequestDispatcher("/item/itemA.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemB.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemB.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemC.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemC.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemD.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemD.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemE.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemE.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemF.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemF.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemG.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemG.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemH.do")) {
RequestDispatcher rd = request.getRequestDispatcher("/item/itemH.jsp");
rd.forward(request, response);
}else if(command.equals("/item/itemAction.do")) {
String itemName = request.getParameter("itemName");
System.out.println("itemName ="+itemName);
String itemquantity = request.getParameter("itemQuantity");
System.out.println("itemquantity =" +itemquantity);
int itemQuantity = Integer.parseInt(itemquantity);
String itemprice1 = request.getParameter("sell_price");
int itemPrice = Integer.parseInt(itemprice1);
String itempricesum1 = request.getParameter("sum");
int itemPriceSum = Integer.parseInt(itempricesum1);
HttpSession session = request.getSession();
int midx = (int)session.getAttribute("midx");
String membername = (String)session.getAttribute("membername");
ItemDao id = new ItemDao();
int value = id.insertItem(itemName, itemQuantity, midx,membername,itemPrice,itemPriceSum);
if(value==1) {
session.setAttribute("Name", itemName);
session.setAttribute("sum", itemPrice);
response.sendRedirect(request.getContextPath()+"/item/pay.do");
}else {
response.sendRedirect(request.getContextPath()+"/item/itemA.do");
}
|
cs |
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
|
public int insertItem(String itemName,int itemQuantity,int midx,String membername,int itemPrice,int itemPricesum) {
int value=0;
PreparedStatement pstmt =null;
String sql = "insert into item(itemidx,itemName,itemQuantity,midx,membername,itemprice,itempricesum)"
+ "values(itemidx_b_seq.nextval,?,?,?,?,?,?)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemName);
pstmt.setInt(2, itemQuantity);
pstmt.setInt(3, midx);
pstmt.setString(4, membername);
pstmt.setInt(5, itemPrice);
pstmt.setInt(6, itemPricesum);
value= pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
return value;
}
|
cs |
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
|
public int insertItem(String itemName,int itemQuantity,int midx,String membername,int itemPrice,int itemPricesum) {
int value=0;
PreparedStatement pstmt =null;
String sql = "insert into item(itemidx,itemName,itemQuantity,midx,membername,itemprice,itempricesum)"
+ "values(itemidx_b_seq.nextval,?,?,?,?,?,?)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemName);
pstmt.setInt(2, itemQuantity);
pstmt.setInt(3, midx);
pstmt.setString(4, membername);
pstmt.setInt(5, itemPrice);
pstmt.setInt(6, itemPricesum);
value= pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
return value;
}
|
cs |
'기존 > 🏀Jsp' 카테고리의 다른 글
[JSP] 결제창 카카오나 이니시스 웹표준 결제창 구현 아임포트 api (0) | 2022.05.31 |
---|---|
[JSP]아이템 구매 리스트 구현 (0) | 2022.05.31 |
[JSP]예약한거 LIST 구현 (예약리스트구현) (0) | 2022.05.31 |
[JSP] 예약하기 페이지 구현 (0) | 2022.05.31 |
[JSP] 게시판 조회수 구현 (0) | 2022.05.31 |