[JSP] 회원가입 / 회원인증 ⑦ - 회원 탈퇴


member/MemberInfo_Del.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:useBean id="memberMgr" class="pack_Member.MemberMgr" />

<%
	String uId = (String)session.getAttribute("idKey");
	boolean res = memberMgr.deleteMember(uId);
	
	if (res){
		session.invalidate();
	}
%>

<script>
	alert("탈퇴가 정상적으로 처리되었습니다. \n확인 버튼을 누르면 메인페이지로 이동합니다.");
	location.href="../Index.jsp";
</script>



pack_Member/MemberMgr.java


package pack_Member;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class MemberMgr {

	private DBConnectionMgr pool;
	
	Connection 			conn 	= null;
	PreparedStatement 	pstmt 	= null;
	ResultSet 			rs 		= null;
	String 				sql 	= null;

	public MemberMgr() {
		try {
			pool = DBConnectionMgr.getInstance();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

    // 회원 탈퇴
	public boolean deleteMember(String uId) {
		
		boolean flag = false;
		
		try {
			conn = pool.getConnection();
			
			sql = "delete from tblMember where uId = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, uId);
			
			int cnt = pstmt.executeUpdate();
			if (cnt > 0)  flag = true;
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			pool.freeConnection(conn, pstmt);
		}
		return flag;
	}
}



Categories:

JSP/Servlet