ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 211025-211029_mini project(delete)
    카테고리 없음 2021. 10. 27. 08:55

    memberdelete.jsp

    <%@page import="data.dao.MemberDao"%>

    <%@ page language="java" contentType="text/html; charset=UTF-8"

        pageEncoding="UTF-8"%>

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <link href="https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap" rel="stylesheet">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <title>Insert title here</title>

    </head>

    <body>

    <!-- 이번엔 모달로 삭제해보기 -->

    <!-- dao에서 만든 비번체크, 삭제메서드 가져와서 처리 -->

    <%

    //모달에서 num,pass 넘겼기에 받기

    String num=request.getParameter("num");

    String pass=request.getParameter("pass");

     

    //dao선언

    MemberDao dao=new MemberDao();

     

    //비번체크후 맞을 경우 삭제, 틀리면 경고후 이전으로

    boolean b=dao.isPassEqual(num, pass);

     

    //만약 b가 true일 때

    if(b){

    dao.deleteMember(num);

    response.sendRedirect("../index.jsp?main=member/memberlist.jsp");

    } else{  

    //만약 틀릴 경우%>

    <script type="text/javascript">

    alert("비밀번호가 틀립니다");

    history.back();

    </script>

    <%}

    %>

    </body>

    </html>

     

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     

     

    memberlist.jsp

    <%@page import="java.text.SimpleDateFormat"%>

    <%@page import="java.util.List"%>

    <%@page import="data.dao.MemberDao"%>

    <%@page import="data.dto.MemberDto"%>

    <%@ page language="java" contentType="text/html; charset=UTF-8"

        pageEncoding="UTF-8"%>

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <link href="https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap" rel="stylesheet">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <title>Insert title here</title>

    </head>

    <body>

    <%

    //dao 선언후 getallmember메서드 호출

    MemberDao dao=new MemberDao();

    List<MemberDto>list=dao.getAllMember();

    %>

     

    <table class="table table-bordered" style="width: 900px;">

      <tr bgcolor="#fff0f5">

        <th width="50">번호</th>

        <th width="70">이름</th>

        <th width="50">아이디</th>

        <th width="150">핸드폰</th>

        <th width="100">주소</th>

        <th width="120">이메일</th>

        <th width="130">가입일</th>

        <th width="140">수정/삭제</th>

      </tr>

      

      <%

      //날짜 형식

      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

      

      for(MemberDto dto:list){ 

      %>

      

      <tr>

        <td><%=dto.getNum() %></td>

        <td><%=dto.getName() %></td>

        <td><%=dto.getId() %></td>

        <td><%=dto.getHp() %></td>

        <td><%=dto.getAddr() %></td>

        <td><%=dto.getEmail() %></td>

        <td><%=sdf.format(dto.getGaipday()) %></td>

        <td>

          <button type="button" class="btn btn-info"

           onclick="location.href='index.jsp?main=member/updatepassform.jsp?num=<%=dto.getNum()%>'">수정</button>

          <button type="button" class="btn btn-danger" 

          onclick="delfunc(<%=dto.getNum()%>)">삭제</button>

    <!-- 자바스크립트를 호출..delfunc -->

        </td>

      </tr>

     

     <%}

      %>

    </table>

     

     

    <!-- 삭제모달 --> 

     <!-- Modal -->

    <div id="myModal" class="modal fade" role="dialog">

      <div class="modal-sm">

     

        <!-- Modal content-->

        <div class="modal-content">

          <div class="modal-header">

            <button type="button" class="close" data-dismiss="modal">&times;</button>

            <h4 class="modal-title">삭제 확인</h4>

          </div>

          <div class="modal-body form-inline">

    <!-- 넘버값 hidden으로 처리 -->

           <input type="hidden" id="delnum">

            <p>삭제 비밀번호: </p>

              <input type="password" id="delpass" class="form-control" style="width: 120px;">

          </div>    

          

          <div class="modal-footer">

            <button type="button" class="btn btn-default delbtn" data-dismiss="modal">삭제</button>

          </div>

        </div>

     

      </div>

    </div>

     

    <!-- 자바스크립트로 처리 -->

    <script type="text/javascript">

    function delfunc(num) {

    alert(num);

    $("#delnum").val(num);  //넘버값 넘기기

    $("#myModal").modal();  //모달창 띄우기

     

     

    //모달삭제버튼 이벤트

    $("button.delbtn").click(function() {

     

    //num,pass 읽기..삭제 파일 호출할 때 거기에 보내기 위해

    var num=$("#delnum").val();

    var pass=$("#delpass").val();

     

    //삭제파일memberdelete 호출

    //삭제안의 모달창이기에 index로 안 보내고 member로 함

    location.href="member/memberdelete.jsp?num="+num+"&pass="+pass;

    });

    }

    </script>

    </body>

    </html>

    댓글

Designed by Tistory.