반응형
adminBoard.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>관리자페이지 - 게시글 관리</title>
<link href="./css/menu.css" rel="stylesheet">
<link href="../css/admin.css?ver=0.12" rel="stylesheet"> <!-- 폴더 안에 있어서 점을 두개 써줘야 함. -->
<!-- <link href="../css/member.css" rel="stylesheet"/> -->
<script type="text/javascript" src="../js/menu.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/xeicon@2.3.3/xeicon.min.css">
</head>
<h1>관리자 페이지</h1>
<body>
<div class="wrap">
<!-- menu -->
<%@ include file="menu.jsp" %>
<!-- 본문내용 -->
<div class="main">
<article>
<h2>게시글 관리</h2>
<div>
<table>
<thead>
<tr>
<td>번호</td>
<td>글제목</td>
<td>작성자</td>
<td>날짜</td>
<td>조회수</td>
<td>댓글</td>
<td>삭제</td>
</tr>
</thead>
<tbody>
<c:forEach items="${list }" var="row">
<tr>
<td class="d1">${row.no }</td>
<td>${row.title }</td>
<td>${row.write }</td>
<td>${row.date }</td>
<td class="d1">${row.count }</td>
<td class="d1">${row.comment }</td>
<td class="d1">${row.del }</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</article>
</div>
</div>
</body>
</html>
adminBoard.java
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cohttp://m.coffee.dao.AdminDAO;
import cohttp://m.coffee.dto.BoardDTO;
import cohttp://m.coffee.util.Util;
@WebServlet("/admin/adminBoard")
public class AdminBoard extends HttpServlet {
private static final long serialVersionUID = 1L;
public AdminBoard() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AdminDAO dao = new AdminDAO();
List<BoardDTO> list = dao.boardList();
request.setAttribute("list", list);
RequestDispatcher rd = request.getRequestDispatcher("adminBoard.jsp");
rd.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
AdminDAO.java
public List<BoardDTO> boardList() {
List<BoardDTO> list = new ArrayList<BoardDTO>();
Connection con = db.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT board_no, board_title, board_date, board_ip, board_del, "
+ " (SELECT count(*) FROM visitcount v WHERE v.board_no=b.board_no) as count,"
+ " (SELECT count(*) FROM comment c WHERE c.board_no=b.board_no) as comment, "
+ " m.mname "
+ " FROM board b"
+ " JOIN member m ON b.mno=m.mno"
+ " ORDER BY board_no DESC";
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
BoardDTO e = new BoardDTO();
e.setNo(rs.getInt("board_no"));
e.setTitle(rs.getString("board_title"));
e.setWrite(rs.getString("mname")); // member에서 옴.
e.setDate(rs.getString("board_date"));
e.setCount(rs.getInt("count")); // visitcount에서 옴.
e.setComment(rs.getInt("comment")); // 댓글에서 옴
e.setIp(rs.getString("board_ip"));
e.setDel(rs.getInt("board_del"));
list.add(e);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs, pstmt, con);
}
return list;
}
}
반응형
'개발 공부 Today I Learned' 카테고리의 다른 글
[국비 51일차 TIL] 관리자페이지에서 IP 확인하기 (0) | 2024.02.01 |
---|---|
[국비 50일차 TIL] 팀 프로젝트 - 우리 반 커뮤니티 사이트 만들기 (포스팅 게시판) (0) | 2024.01.30 |
[국비 48일차 TIL] 관리자 페이지 설정 member, admin (1) | 2024.01.26 |
[국비 47일차 TIL] 댓글 수정버튼 눌렀을 때 (0) | 2024.01.25 |
[국비 46일차 TIL ] 댓글 삭제 수정 기능 구현 (0) | 2024.01.24 |
댓글