#boardContent.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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <% pageContext.setAttribute("newLine", "\n"); %> <c:set var="ctp" value="${pageContext.request.contextPath}"/> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>boardContent.jsp</title> <jsp:include page="/include/bs4.jsp" /> <style> th { text-align: center; background-color: #eee; } </style> <script> 'use strict'; // 좋아요 누르기 function goodCheck() { location.href = "${ctp}/BoardGoodCheck.bo?idx=${vo.idx}"; } // 게시글 삭제 function boardDelete() { let ans = confirm("현 게시글 삭제하시겠습니까?"); if(ans) { location.href="${ctp}/BoardDelete.bo?idx=${vo.idx}&pag=${pag}&pageSize=${pageSize}&nickName=${vo.nickName}"; } } // 댓글 달기(ajax로 처리) function replyCheck() { let content = $("#content").val(); if(content.trim() == ""){ alert("댓글을 입력하세요"); $("#content").focus(); return false; } /* 자바스크립트에서 객체를 만드는 방법이다. */ let query = { boardIdx : ${vo.idx}, mid : '${sMid}', nickName : '${sNickName}', content : content, hostIp : '${pageContext.request.remoteAddr}' /* hostIp : '<%=request.getRemoteAddr() %>' 와 같은 표현이다.*/ } $.ajax({ type : 'post', url : '${ctp}/BoardReplyInput.bo', data : query, success : function(res) { if(res == '1') { alert('댓글이 입력되었습니다.'); location.reload(); } else { alert('댓글이 입력되지 않았습니다.'); } }, error : function() { alert("전송되지 못했습니다."); } }); } // 댓글 삭제(ajax이용) function replyDelete(replyIdx) { let ans = confirm("선택한 댓글을 삭제하시겠습니까?"); if(!ans) return false; $.ajax({ type : 'post', url : '${ctp}/BoardReplyDelete.bo', data : {replyIdx : replyIdx}, success : function(res) { if(res == '1') { alert('댓글이 삭제되었습니다.'); location.reload(); } else { alert('댓글이 삭제되지 않았습니다.'); location.reload(); } }, error : function() { alert('전송되지 못했습니다.'); } }); } </script> </head> <body> <jsp:include page="/include/header.jsp" /> <p><br/></p> <div class="container"> <h2 class="text-center">글 내 용</h2> <br/> <table class="table table-borderless m-0 p-0"> <tr> <td class="text-left">공개 여부 : ${vo.openSw}</td> <td class="text-right">접속IP : ${vo.hostIp}</td> </tr> </table> <table class="table table-bordered"> <tr> <th>글쓴이</th> <td>${vo.nickName}</td> <th>작성 날짜</th> <td>${fn:substring(vo.wDate,0,fn:length(vo.wDate))}</td> </tr> <tr> <th>제목</th> <td colspan="3">${vo.title}</td> </tr> <tr> <th>이메일</th> <td>${vo.email}</td> <th>조회수</th> <td>${vo.readNum}</td> </tr> <tr> <th>홈페이지</th> <td>${vo.homePage}</td> <th>좋아요</th> <td> ${vo.good} (<a href="xxxxjavascript:goodCheck()">❤</a>) </td> </tr> <tr> <th>내용</th> <td colspan="3" style="height:250px">${fn:replace(vo.content, newLine,"<br/>")}</td> </tr> <tr> <td colspan="4" class="text-center"> <c:if test="${flag == 'search'}"> <input type="button" value="돌아가기" xxxxonclick="location.href='${ctp}/BoardSearch.bo?search=${search}&searchString=${searchString}&pag=${pag}&pageSize=${pageSize}';" class="btn btn-primary"/> </c:if> <c:if test="${flag != 'search'}"> <input type="button" value="돌아가기" xxxxonclick="location.href='${ctp}/BoardList.bo?pag=${pag}&pageSize=${pageSize}';" class="btn btn-primary mr-3"/> <c:if test="${sMid == vo.mid || sLevel == 0}"> <!-- 아이디가 로그인한 사용자와 같거나 관리자는, 수정/삭제 가능! --> <input type="button" value="수정" xxxxonclick="location.href='${ctp}/BoardUpdate.bo?pag=${pag}&pageSize=${pageSize}&idx=${vo.idx}';" class="btn btn-success mr-3"/> <input type="button" value="삭제" xxxxonclick="boardDelete()" class="btn btn-danger"/> </c:if> </c:if> </td> </tr> </table> <c:if test="${flag != 'search'}"> <!-- 이전글/ 다음글 처리 --> <table class="table table-borderless"> <tr> <td> <c:if test="${nextVo.nextIdx != 0}"> <a href="${ctp}/BoardContent.bo?idx=${nextVo.nextIdx}&pageSize=${pageSize}&pag=${pag}" >다음글 : 다음글 제목 ${nextVo.nextTitle}</a><br/> </c:if> <c:if test="${preVo.preIdx != 0}"> <a href="${ctp}/BoardContent.bo?idx=${preVo.preIdx}&pageSize=${pageSize}&pag=${pag}" >이전글 : 이전글 제목 ${preVo.preTitle}</a> </c:if> </td> </tr> </table> </c:if> <!-- 댓글 리스트 보여주기 --> <div class="container"> <table class="table table-hover text-left"> <tr> <th> 작성자</th> <th>댓글</th> <th>작성일자</th> <th>접속 IP</th> </tr> <c:forEach var="replyVo" items="${replyVos}" varStatus="st"> <tr> <td> <c:if test="${sMid == replyVo.mid || sLevel == 0}"> <a href="xxxxjavascript:replyDelete(${replyVo.idx})"><span class="badge badge-pill badge-danger">❌</span></a> </c:if> ${replyVo.nickName} </td> <td>${fn: replace(replyVo.content, newLine, "<br/>")}</td> <td class="text-center">${fn: replace(replyVo.wDate,0,10)}</td> <td class="text-center">${replyVo.hostIp}</td> </tr> </c:forEach> </table> </div> <!-- 댓글 입력창 --> <form name="replyForm"> <table class="table table-center"> <tr> <td style="width:85%" class="text-left"> 댓글 : <textarea rows="4" name="content" id="content" class="form-control"></textarea> </td> <td style="width:15%" class="text-center"> <br/> <p>작성자: ${sNickName}</p> <p><input type="button" value="댓글 달기" xxxxonclick="replyCheck()" class="btn btn-info btn-sm"/></p> </td> </tr> </table> </form> </div> <p><br/></p> <jsp:include page="/include/footer.jsp" /> </body> </html> | cs |
#BoardController.java : 내용 추가
#BoardReplyDelete.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | package board; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class BoardReplyDeleteCommand implements BoardInterface { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int replyIdx = request.getParameter("replyIdx")==null? 0: Integer.parseInt(request.getParameter("replyIdx")); BoardDAO dao = new BoardDAO(); String res = dao.setReplyDeleteOk(replyIdx); response.getWriter().write(res); } } | cs |
#BoardDAO.java : 내용 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // 달린 댓글 삭제 public String setReplyDeleteOk(int replyIdx) { String res = "0"; try { sql = "delete from boardReply where idx=?"; pstmt = conn.prepareStatement(sql); pstmt.setInt(1, replyIdx); pstmt.executeUpdate(); res = "1"; } catch (SQLException e) { System.out.println("SQL 오류 : " + e.getMessage()); } finally { getConn.pstmtClose(); } return res; } | cs |
첫댓글 댓글이 삭제되지않았으면, 굳이 reload할필요는 없겠죠~
좋아요~~ 수고하셨습니다.