프로젝트 구조 : 게시글 삭제시 비밀번호를 확인할 boardRemoveForm.jsp와 글삭제하는 boardRemoveAction.jsp 추가
0_2강좌의 boardView.jsp파일 44번째 라인에 글을 삭제할 수 있는 링크 추가
1 2 3 4 | <div> <a href="">수정</a> <a href="<%=request.getContextPath()%>/board/boardRemoveForm.jsp?boardNo=<%=boardNo%>">삭제</a> </div> | cs |
boardRemoveForm.jsp : 삭제시 확인할 비밀번호 입력
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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>BOARD REMOVE FORM</title> </head> <body> <% if(request.getParameter("boardNo") == null) { response.sendRedirect(request.getContextPath()+"/board/boardList.jsp"); } else { %> <form action="<%=request.getContextPath()%>/board/boardRemoveAction.jsp" method="post"> <input name="boardNo" value="<%=request.getParameter("boardNo")%>" type="hidden"/> <div>비밀번호확인 :</div> <div><input name="boardPw" type="password"></div> <div> <input type="submit" value="삭제"/> <input type="reset" value="초기화"/> </div> </form> <% } %> </body> </html> | cs |
boardRemoveAction.jsp : 비밀번호가 일치하면 글삭제
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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import="java.sql.*" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>BOARD REMOVE ACTION</title> </head> <body> <% if(request.getParameter("boardNo") == null || request.getParameter("boardPw") == null) { response.sendRedirect(request.getContextPath()+"/board/boardList.jsp"); } else { int boardNo = Integer.parseInt(request.getParameter("boardNo")); System.out.println("boardNo :"+boardNo); String boardPw = request.getParameter("boardPw"); System.out.println("boardPw :"+boardPw); String dbUrl = "jdbc:mysql://127.0.0.1:3306/injava?useUnicode=true&characterEncoding=euckr"; String dbUser = "root"; String dbPw = "java0000"; Connection connection = null; PreparedStatement statement = null; try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(dbUrl, dbUser, dbPw); String sql = "DELETE FROM board WHERE board_no=? AND board_pw=?"; statement = connection.prepareStatement(sql); statement.setInt(1, boardNo); statement.setString(2, boardPw); if(statement.executeUpdate()==1){ response.sendRedirect(request.getContextPath()+"/board/boardList.jsp"); } else { response.sendRedirect(request.getContextPath()+"/board/boardRemoveForm.jsp?boardNo="+boardNo); } } catch(Exception e) { e.printStackTrace(); out.print("BOARD REMOVE ERROR!"); } finally { try {statement.close();} catch(Exception e){} try {connection.close();} catch(Exception e){} } } %> </body> </html> | cs |
'P. 자바 미니 프로젝트 > jsp 게시판' 카테고리의 다른 글
P.1.5 JSP 게시판 만들기5 - 글수정 (0) | 2016.11.09 |
---|---|
P.1.3 JSP 게시판 만들기3 - 글내용 (0) | 2016.11.09 |
P.1.2 JSP 게시판 만들기2 - 글목록 (0) | 2016.11.04 |
P.1.1 JSP 게시판 만들기1 - 글입력 (0) | 2016.11.04 |