JSP/MVC_BBS
view.jsp
GAWON
2023. 6. 16. 18:22
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
div {
width: 800px;
margin: auto;
text-align: center;
}
table {
width: 800px;
text-align: left;
border-collapse: collapse;
}
td,th {
border : 1px solid #1e90ff;
padding: 10px;
}
th {
width: 130px;
text-align: center;
background-color: #0078ff;
color: white;
}
#btn {
text-align: center;
}
h1 {
color : #0078ff;
}
.insertComment th {
border : 1px solid #1e90ff;
width: 130px;
text-align: center;
background-color: #00a5ff;
color: white;
}
.viewComment th {
border : 1px solid #1e90ff;
width: 130px;
text-align: center;
background-color: #87cefa;
color: white;
}
.viewComment td{
text-align: center;
}
.viewComment #num {
width:50px;
}
.viewComment #writer {
width:100px;
}
.viewComment #con {
width:250px;
}
.viewComment #date {
width:100px;
}
.viewComment #del {
width:50px;
}
textarea {
resize: none;
}
.readonly{
background-color: lightgray;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
function update_page(f){
var cmd = "<input type='hidden' name='cmd' value='updatePage'/>";
$(f).append(cmd);
f.action = 'BBSController';
f.submit();
}
function remove_page(f){
if(confirm("해당 게시글을 삭제하시겠습니까??")){
var cmd = "<input type='hidden' name='cmd' value='removeBBS'/>";
$(f).append(cmd);
f.action = 'BBSController';
f.submit();
}
}
function view_all(){
var cp = '${currentPage}';
location.href='BBSController?cmd=allList¤tPage=' + cp;
}
//------댓글
function insert_comment(f){
f.action='BBSController';
f.submit();
}
function remove_comment(pw, c_idx, b_idx){
var ckPw = prompt("댓글 비밀번호를 입력하세요.");
var cp = '${currentPage}';
if(ckPw != pw){
alert("비밀번호가 일치하지 않습니다.");
return;
}
location.href = 'BBSController?cmd=removeComment&c_idx=' + c_idx + "&b_idx=" + b_idx + "¤tPage=" + cp;
}
</script>
</head>
<body>
<div>
<h1>${bvo.b_idx }번 게시글</h1>
<form method="post">
<table class="bbs">
<tbody>
<tr>
<th>작성자</th>
<td>${bvo.writer }</td>
<th>IP</th>
<td>${bvo.ip }</td>
</tr>
<tr>
<th>제목</th>
<td colspan="3">${bvo.title }</td>
</tr>
<tr>
<th>첨부파일</th>
<td colspan="3">
<c:choose>
<c:when test="${bvo.filename eq null }">
첨부파일 없음
</c:when>
<c:otherwise>
<a href="BBSController?cmd=download&path=upload&filename=${bvo.filename}">${bvo.filename}</a>
</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<th>내용</th>
<td colspan="3">${bvo.content }</td>
</tr>
<tr>
<td colspan="4" id="btn">
<c:if test="${bvo.writer == member.mid}">
<input type="button" value="게시글 수정하기" onclick="update_page(this.form)">
<input type="button" value="게시글 삭제하기" onclick="remove_page(this.form)">
</c:if>
<input type="button" value="목록으로 이동" onclick="view_all()">
<!-- 현재 페이지 번호를 가지고 페이지 이동을 한다. -->
<input type="hidden" name="currentPage" value="${currentPage }">
<input type="hidden" name="b_idx" value="${bvo.b_idx }">
</td>
</tr>
</tbody>
</table>
</form>
<br/><hr/><br/>
<!-- 댓글 입력 폼 -->
<form method="post">
<table class="insertComment">
<tbody>
<tr>
<th>댓글 작성자</th>
<td>
<c:if test="${not empty member }">
<input type="text" name="writer" value="${member.mid }" readonly class="readonly"/>
</c:if>
<c:if test="${empty member }">
<input type="text" name="writer" readonly class="readonly"/>
</c:if>
<th>댓글 비밀번호</th>
<td><input type="password" name="pw"></td>
</tr>
<tr>
<th>댓글 내용</th>
<td colspan="3">
<textarea rows="3" cols="80" name="content" placeholder="댓글을 입력하세요"></textarea>
</td>
</tr>
<tr>
<td colspan="4" id="btn">
<c:if test="${not empty member }">
<input type="button" value="댓글 등록" onclick="insert_comment(this.form)">
<input type="reset" value="다시 작성">
</c:if>
<input type="hidden" name="b_idx" value="${bvo.b_idx }">
<input type="hidden" name="currentPage" value="${currentPage }">
<input type="hidden" name="cmd" value="insertComment">
</td>
</tr>
</tbody>
</table>
</form>
<br/><hr/><br/>
<!-- 댓글 출력 폼 -->
<form method="post">
<table class="viewComment">
<thead>
<tr>
<th id="num">번호</th>
<th id="writer">작성자</th>
<th id="con">내용</th>
<th id="date">작성일</th>
<th id="del">삭제</th>
</tr>
</thead>
<tbody>
<c:choose>
<c:when test="${not empty cList }">
<c:forEach var="cvo" items="${cList }">
<tr>
<td>${cvo.c_idx }</td>
<td>${cvo.writer }</td>
<td>${cvo.content }</td>
<td>${cvo.reg_date }</td>
<td>
<c:if test="${member.mid == cvo.writer }">
<a href="javascript:remove_comment(${cvo.pw }, ${cvo.c_idx }, ${bvo.b_idx } );">삭제</a>
</c:if>
</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr>
<td colspan="5">댓글이 없습니다.</td>
</tr>
</c:otherwise>
</c:choose>
</tbody>
</table>
</form>
</div>
</body>
</html>