상품등록 예제
filter에서 추가된 로그인 화면 web.xml에서 설정했다.
등록부분 처리하는 processAddProduct 를 수정한다.
product 테이블에 inset하는 코드 추가
processAddProduct.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.util.Enumeration"%>
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@page import="kr.gov.dto.Product"%>
<%@page import="kr.gov.dao.ProductRepository"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="dbconn.jsp" %>
<%
request.setCharacterEncoding("UTF-8");
//addProduct.jsp에서 사용자가 업로드한 이미지 부분을 받아저장.
String filename = "";
/* String realFolder = "C:\\workspace-jsp\\upload"; */ //웹 애플리케이션에서 절대경로
String realFolder = "C:\\workspace-jsp\\WebStore\\WebContent\\resources\\images";
int maxsize = 100 * 1024 * 1024; //최대 업로드 크기
String encType = "UTF-8"; //인코딩 유형
MultipartRequest multi = new MultipartRequest(request, realFolder, maxsize,
encType, new DefaultFileRenamePolicy());
/* addProduct.jsp에서 사용자가 입력한 부분 받아서 저장 */
String productId = multi.getParameter("productId"); //상품 아이디
String pname = multi.getParameter("pname"); //상품
String unitprice = multi.getParameter("unitprice"); //상품가격
String description = multi.getParameter("description"); //상품 설명
String menufecturer = multi.getParameter("menufecturer"); //제조사
String category = multi.getParameter("category"); //분류
String numberOfstock = multi.getParameter("numberOfstock"); //재고 수
String condition = multi.getParameter("condition"); //신상품 or 중고품 or 재생품
Integer price;
long stock;
//단가 입력창에 미 입력시에
if(unitprice.isEmpty()){
price = 0; //오토박싱
}
else {
//String을 Integer로 변환
price = Integer.valueOf(unitprice);
}
if(numberOfstock.isEmpty()){
stock = 0;
}
else {
//String을 long타입으로 변환
stock = Long.valueOf(numberOfstock);
}
Enumeration files = multi.getFileNames();
String fname = (String)files.nextElement();
String fileName = multi.getFilesystemName(fname);
//아래 내용을 DB입력으로 대체
/*
ProductRepository dao = ProductRepository.getInstance();
Product newProduct = new Product();
//Product 객체에 사용자가 입력한 내용을 저장
newProduct.setProductId(productId);
newProduct.setPname(pname);
newProduct.setUnitprice(price);
newProduct.setDescription(description);
newProduct.setMenufecturer(menufecturer);
newProduct.setCategory(category);
newProduct.setNumberOfstock(stock);
newProduct.setCondition(condition);
//이미지 저장 부분
newProduct.setFilename(fileName);
//Arraylist에 새상품을 추가
dao.addProduct(newProduct);
*/
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/webstoredb?serverTimezone=UTC";
String user = "root";
String password = "7496";
Class.forName("com.mysql.cj.jdbc.Driver"); //드라이버명
conn = DriverManager.getConnection(url, user, password); //연결객체생성
PreparedStatement pstmt = null;
String sql = "insert into product values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
pstmt = conn.prepareStatement(sql);
/* 9개의 사용자로부터 입력받은 데이터를 DB에 저장 */
pstmt.setString(1, productId);
pstmt.setString(2, pname);
pstmt.setInt(3, price);
pstmt.setString(4, description);
pstmt.setString(5, menufecturer);
pstmt.setString(6, category);
pstmt.setLong(7, stock);
pstmt.setString(8, condition);
pstmt.setString(9, fileName);
pstmt.executeUpdate();
System.out.println("상품 등록 완료");
//자원 해제
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
//페이지 이동시킴
response.sendRedirect("products.jsp");
%>
상품수정, 상품삭제 예제
get 방식으로 넘겨준다 같은페이지 활용(수정, 삭제)
menu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<nav class="navbar navbar-expand navbar-dark bg-dark"><!-- 네비게이션 바를 만듬 -->
<div class="container"> <!-- container라는 클래스부터 내용을 표시함 -->
<div class="navbar-header"> <!-- 네비게이션 헤더 -->
<a class="navbar-brand" href="./welcome.jsp">HOME</a>
</div>
<!-- 네비게이션 바 요소를 추가등록 -->
<div>
<ul class="navbar-nav mr-auto"> <!-- mr-auto : 마진공간 자동설정 -->
<li class="nav-item"><a href="products.jsp" class="nav-link">상품목록</a></li>
<li class="nav-item"><a href="addProduct.jsp" class="nav-link">상품등록</a></li>
<li class="nav-item"><a href="editProduct.jsp?edit=update" class="nav-link">상품수정</a></li>
<li class="nav-item"><a href="editProduct.jsp?edit=delete" class="nav-link">상품삭제</a></li>
</ul>
</div>
</div>
</nav>
제약조건 추가해줘야 한다. web.xml 제약조건 추가 부분
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>WebStore</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 404에러가 발생하면 자동으로 exceptionNoPage.jsp 페이지 보여주게 된다. -->
<error-page>
<error-code>404</error-code>
<location>/exceptionNoPage.jsp</location>
</error-page>
<!-- 시큐리티 역할 추가 -->
<security-role>
<description>관리자</description>
<role-name>admin</role-name>
</security-role>
<!-- 제약조건 추가 -->
<security-constraint>
<display-name>WebStore Security</display-name>
<web-resource-collection> <!-- 웹자원 제약조건 설정 -->
<web-resource-name>WebStore</web-resource-name> <!-- 프로젝트 이름 -->
<description></description>
<url-pattern>/addProduct.jsp</url-pattern> <!-- 상품등록 페이지 -->
<url-pattern>/editProduct.jsp</url-pattern> <!-- 상품수정 페이지 -->
</web-resource-collection>
<auth-constraint> <!-- 권한 제약조건 설정 -->
<description>권한 관리자명</description>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config> <!-- 시큐리티 인증 설정 -->
<auth-method>FORM</auth-method> <!-- 폼 인증처리 방식 -->
<form-login-config>
<form-login-page>/login.jsp</form-login-page> <!-- 로그인이 성공할 경우 -->
<form-error-page>/login_failed.jsp</form-error-page> <!-- 로그인이 실패할 경우 -->
</form-login-config>
</login-config>
<!-- 필터 적용 -->
<filter>
<filter-name>LogFilter</filter-name>
<filter-class>kr.gov.filter.LogFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LogFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 필터(파일기록) 적용 -->
<filter>
<filter-name>LogFileFilter</filter-name>
<filter-class>kr.gov.filter.LogFileFilter</filter-class>
<init-param>
<param-name>filename</param-name> <!-- 로그 기록을 남길 파일 경로 지정 -->
<param-value>C:\\workspace-jsp\\log\\webstore.log</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LogFileFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
get 방식으로 넘겨받아서 같은페이지 활용됨(수정, 삭제)
editProduct.jsp
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String edit = request.getParameter("edit"); //메뉴 "상품수정" 클릭시 넘어오는 edit값 받음.
DecimalFormat dFormat = new DecimalFormat("###,###");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 수정 - WebStore</title>
<link rel="stylesheet" href="./resources/css/bootstrap.min.css">
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">상품 수정</h1>
</div>
</div>
<div class="container">
<div class="row" align="center">
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/webstoredb?serverTimezone=UTC";
String user = "root";
String password = "7496";
Class.forName("com.mysql.cj.jdbc.Driver"); //드라이버명
conn = DriverManager.getConnection(url, user, password); //연결객체생성
%>
<%
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select * from product";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
%>
<div class="col-md-4">
<img alt="사진" src="${pageContext.request.contextPath}/resources/images/<%=rs.getString("filename") %>"
style="width: 100%">
<h3><%=rs.getString("pname") %></h3>
<p><%=rs.getString("description") %>
<p><%=dFormat.format(Integer.parseInt(rs.getString("unitprice"))) %>
<p><%
if(edit.equals("update")) {
%>
<a href="./updateProduct.jsp?id=<%=rs.getString("productId") %>"
class="btn btn-success" role="button">수정 »</a>
<%
}
else if(edit.equals("delete")) {
%>
<a href="#" onclick="deleteConfirm('<%=rs.getString("productId") %>')"
class="btn btn-danger" role="button">삭제 »</a>
<%
}
%>
</div>
<%
}
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
%>
</div>
<hr>
</div>
<jsp:include page="footer.jsp"></jsp:include>
<script type="text/javascript">
function deleteConfirm(id) {
if(confirm("해당 상품을 삭제합니다!") == true) {
location.href = "./deleteProduct.jsp?id=" + id;
}
else
return;
}
</script>
</body>
</html>
상품 수정하는 페이지
updateProduct.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.text.DecimalFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
DecimalFormat dFormat = new DecimalFormat("###,###");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 수정 - WebStore</title>
<link rel="stylesheet" href="./resources/css/bootstrap.min.css" />
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">상품 수정</h1>
</div>
</div>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/webstoredb?serverTimezone=UTC";
String user = "root";
String password = "7496";
Class.forName("com.mysql.cj.jdbc.Driver"); //드라이버명
conn = DriverManager.getConnection(url, user, password); //연결객체생성
%>
<%
String productId = request.getParameter("id"); /* 어떤 제품 수정할지 id값 넘어오는것 받음. */
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select * from product where productId = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, productId);
rs = pstmt.executeQuery();
if(rs.next()) {
%>
<div class="container">
<div class="row">
<div class="col-md-5">
<img alt="사진" src="${pageContext.request.contextPath}/resources/images/<%= rs.getString("filename") %>"
style="width: 100%">
</div>
<div class="col-md-7">
<form action="./processUpdateProduct.jsp" name="newProduct" class="form-horizontal"
method="post" enctype="multipart/form-data">
<div class="form-group row">
<label class="col-sm-3">상품코드</label>
<div class="col-sm-3">
<input type="text" id="productId" name="productId" class="form-control"
value='<%= rs.getString("productId") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">상품명</label>
<div class="col-sm-3">
<input type="text" id="pname" name="pname" class="form-control"
value='<%= rs.getString("pname") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">가격</label>
<div class="col-sm-3">
<input type="text" id="unitprice" name="unitprice" class="form-control"
value='<%= rs.getString("unitprice") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">상세 설명</label>
<div class="col-sm-3">
<input type="text" id="description" name="description" class="form-control"
value='<%= rs.getString("description") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">제조사</label>
<div class="col-sm-3">
<input type="text" id="menufecturer" name="menufecturer" class="form-control"
value='<%= rs.getString("menufecturer") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">분류</label>
<div class="col-sm-3">
<input type="text" id="category" name="category" class="form-control"
value='<%= rs.getString("category") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">재고 수</label>
<div class="col-sm-3">
<input type="text" id="numberOfStock" name="numberOfStock" class="form-control"
value='<%= rs.getString("numberOfStock") %>'>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">상태</label>
<div class="col-sm-5">
<input type="radio" name="condition" value="New">신규 제품<br/>
<input type="radio" name="condition" value="Old">중고 제품<br/>
<input type="radio" name="condition" value="Refurbished">재생 제품<br/>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3">이미지</label>
<div class="col-sm-5">
<input type="file" name="filename" class="form-control">
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm-2">
<input type="submit" class="btn btn-primary" value="수정완료">
</div>
</div>
</form>
</div>
</div>
</div>
<%
}
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
%>
</body>
</html>
수정 처리 페이지
processUpdateProduct.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.util.Enumeration"%>
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/webstoredb?serverTimezone=UTC";
String user = "root";
String password = "7496";
Class.forName("com.mysql.cj.jdbc.Driver"); //드라이버명
conn = DriverManager.getConnection(url, user, password); //연결객체생성
%>
<%
request.setCharacterEncoding("UTF-8");
//addProduct.jsp에서 사용자가 업로드한 이미지 부분을 받아저장.
String filename = "";
//String realFolder = "C:\\workspace-jsp\\upload"; //웹 애플리케이션에서 절대경로
String realFolder = "C:\\workspace-jsp\\WebStore\\WebContent\\resources\\images";
int maxsize = 10 * 1024 * 1024; //최대 업로드 크기(10M)
String encType = "utf-8"; //인코딩 유형
MultipartRequest multi = new MultipartRequest(request, realFolder, maxsize,
encType, new DefaultFileRenamePolicy());
/* addProduct.jsp에서 사용자가 입력한 부분 받아서 저장 */
String productId = multi.getParameter("productId"); //상품 아이디
String pname = multi.getParameter("pname"); //상품명
String unitprice = multi.getParameter("unitprice"); //상품 가격
String description = multi.getParameter("description"); //상품 설명
String manufacturer = multi.getParameter("menufecturer"); //제조사
String category = multi.getParameter("category"); //분류
String numberOfStock = multi.getParameter("numberOfStock"); //재고 수
String condition = multi.getParameter("condition"); //신상품 or 중고품 or 재생품
Integer price;
long stock;
//단가 입력창에 미 입력시에
if(unitprice.isEmpty()) {
price = 0; //오토박싱
}
else {
//String을 숫자로 변환함.
price = Integer.valueOf(unitprice);
}
//재고수량 입력창에 미 입력시에
if(numberOfStock.isEmpty()) {
stock = 0;
}
else {
//String을 long타입으로 변환함.
stock = Long.valueOf(numberOfStock);
}
Enumeration files = multi.getFileNames();
String fname = (String)files.nextElement();
String fileName = multi.getFilesystemName(fname);
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select * from product where productId = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, productId);
rs = pstmt.executeQuery();
if(rs.next()) {
if(fileName != null) {
sql = "update product set pname=?, unitPrice=?, description=?, menufecturer=?, " +
"category=?, numberOfStock=?, conditions=?, filename=? where productId=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, pname);
pstmt.setInt(2, price);
pstmt.setString(3, description);
pstmt.setString(4, manufacturer);
pstmt.setString(5, category);
pstmt.setLong(6, stock);
pstmt.setString(7, condition);
pstmt.setString(8, fileName);
pstmt.setString(9, productId);
pstmt.executeUpdate();
}
else { /* 이미지 변경이 없다면 */
sql = "update product set pname=?, unitPrice=?, description=?, menufecturer=?, " +
"category=?, numberOfStock=?, conditions=? where productId=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, pname);
pstmt.setInt(2, price);
pstmt.setString(3, description);
pstmt.setString(4, manufacturer);
pstmt.setString(5, category);
pstmt.setLong(6, stock);
pstmt.setString(7, condition);
pstmt.setString(8, productId);
pstmt.executeUpdate();
}
}
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
response.sendRedirect("editProduct.jsp?edit=update");
%>
상세보기 DB연동 결과
product.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="kr.gov.dto.Product"%>
<%@page import="kr.gov.dao.ProductRepository"%>
<%@page errorPage="exceptionNoProductId.jsp" %> <!-- id값이 유효하지 않으면 에러페이지로 이동시킨다. -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- <jsp:useBean id="productDAO" class="kr.gov.dao.ProductRepository" scope="session"/> --%>
<%
request.setCharacterEncoding("UTF-8");
DecimalFormat dFormat = new DecimalFormat("###,###");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 상세 정보 - WebStroe</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css">
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="jumbotron">
<div class="contaner">
<h1 class="display-3">상품 정보</h1>
</div>
</div>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/webstoredb?serverTimezone=UTC";
String user = "root";
String password = "7496";
Class.forName("com.mysql.cj.jdbc.Driver"); //드라이버명
conn = DriverManager.getConnection(url, user, password); //연결객체생성
%>
<%
//넘어온 상품 아이디값을 얻었다.
String productId =request.getParameter("id");
/*
ProductRepository dao = ProductRepository.getInstance();
//넘어온 상품아이디값을 이용해 실제 해당되는 Product객체를 얻음.
Product product = dao.getProductById(id);
*/
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select * from product where productId = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, productId);
rs = pstmt.executeQuery();
if(rs.next()) {
%>
<div class="container">
<div class="row">
<div class="col-md-5">
<%-- <img alt="" src="C:/workspace-jsp/upload/<%=product.getFilename() %>" style="width:100%"> --%>
<img alt="" src="${pageContext.request.contextPath}/resources/images/<%=rs.getString("filename") %>" style="width:100%">
</div>
<div class="col-md-6">
<h3><%=rs.getString("pname") %></h3>
<p><%=rs.getString("description") %></p>
<p><b>상품 코드 :</b><span class="badge badge-danger" ><%=rs.getString("productId") %><span></b></p>
<p><b>제조사 : </b><%=rs.getString("menufecturer") %></p>
<p><b>분류 : </b><%=rs.getString("category") %></p>
<p><b>제고 수 : </b><%=dFormat.format(rs.getLong("numberOfstock")) %></p>
<h4><%=dFormat.format(rs.getInt("unitprice")) %>원</h4>
<p><form name="addForm" action="./addCart.jsp?id=<%=rs.getString("productId") %>" method="post">
<!-- 상품 주문을 클릭하면 자바스크립트 핸들러 함수 addToCart()호출 -->
<a href="#" class="btn btn-info" onclick="addToCart()">상품 주문»</a>
<!-- 장바구니 버튼 추가, 클릭시 /cart.jsp로 이동함 -->
<a href="./cart.jsp" class="btn btn-warning">장바구니»</a>
<a href="./products.jsp" class="btn btn-secondary">상품 목록»</a>
</form>
</div>
<%
}
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
%>
</div>
<hr>
</div>
<jsp:include page="footer.jsp"/>
<script type="text/javascript">
/* 장바구니에 추가하기 위한 헨들러 함수 */
function addToCart() {
if(confirm('해당 상품을 장바구니에 추가하겠습니까?')) { /* confirm() : 사용자가 선택할 때 이용(확인, 취소) */
document.addForm.submit();
}
else {
document.addForm.reset();
}
}
</script>
</body>
</html>
상품 삭제하기
deleteProduct.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/webstoredb?serverTimezone=UTC";
String user = "root";
String password = "7496";
Class.forName("com.mysql.cj.jdbc.Driver"); //드라이버명
conn = DriverManager.getConnection(url, user, password); //연결객체생성
%>
<%
String productId = request.getParameter("id"); /* 어떤 제품 삭제할지 id값 넘어오는 것 */
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "select * from product";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
//rs에 있는 물품과 id값으로 저장해놓은 것과 일치하는 것이 있다면.
if(rs.next()) {
sql = "delete from product where productId = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, productId);
pstmt.executeUpdate();
}
else {
out.println("일치하는 상품이 없습니다.");
}
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
response.sendRedirect("editProduct.jsp?edit=delete");
%>