min's devlog

[JSP] 주소록 데이터 삭제 본문

til/Server

[JSP] 주소록 데이터 삭제

값진 2022. 6. 27. 09:09

del.jsp

//1. 데이터 가져오기(?seq=5)
//2. delok.jsp?seq=5 전달하기
<main>
		<header>
			<%@ include file="inc/header.jsp" %>
		</header>
		<section>
			<div class="section content">
				
				<div class="btns">
					<input type="button" value="돌아가기" class="btn btn-secondary" onclick="location.href='/jsp/address/list.jsp';">
					<input type="button" value="삭제하기" class="btn btn-primary" onclick="location.href='/jsp/address/delok.jsp?seq=<%= seq %>';">
				</div>
				
			</div>
		</section>	
	</main>

</body>
</html>

delok.jsp

	//2. 데이터 가져오기
	//3. DB 작업
	//	3.1 DB 연결
	//	3.2 SQL
	//	3.3 종료
	//4. 마무리(feedback)
	
	//2.
	String seq = request.getParameter("seq");
		
	int result = 0;
	
	try {
		//3.
		DBUtil util = new DBUtil();
		
		Connection conn = null;
		Statement stat = null;
		PreparedStatement pstat = null;		
		conn = util.open();		
		
		String sql = "delete from tblAddress where seq = ?";	
		pstat = conn.prepareStatement(sql);
		pstat.setString(1, seq);		
		result = pstat.executeUpdate();		
		
		//4.
		if (result > 0) {
			//추가 성공
		} else {
			//추가 실패
		}
	
	} catch (Exception e) {
		System.out.println(e);
	}
	
%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="/address/inc/asset.jsp" %>
<style>

</style>
</head>
<body>
	<main>
		<header>
			<%@ include file="inc/header.jsp" %>
		</header>
		<section>
			<div class="section content">
				
				<%-- 
				<% if (result > 0) { %>
				
				<div>추가 성공!!</div>
				<a href="list.jsp">목록 보기</a>
				
				<% } else { %>
				
				<div>추가 실패;;</div>
				<a href="#!" onclick="history.back();">돌아가기</a>
				
				<% } %> 
				--%>
				
			</div>
		</section>	
	</main>
	
	<script>
	
		<%-- 
		<% if (result > 0) { %>
		
		alert('추가 성공!!');
		location.href = 'list.jsp';
		
		<% } else { %>
		
		alert('추가 실패;;');
		history.back();
		
		<% } %> 
		--%>
				
		<% if (result > 0) { %>		
		location.href = 'list.jsp';		
		<% } else { %>		
		alert('삭제 실패;;');
		history.back();	
		<% } %> 
	</script>
</body>

'til > Server' 카테고리의 다른 글

Code template  (0) 2022.06.27
[JSP] 웹 인증  (0) 2022.06.27
[JSP] 주소록에 데이터 추가  (0) 2022.06.24
[JSP] MVC의 모델, 뷰, 컨트롤러  (0) 2022.06.23
[JSP] Model2 구조와 MVC 패턴  (0) 2022.06.23
Comments