- Bootstrap 무료 테마 사이트
1. 게시글 목록조회 페이지
- list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<%@ include file="../common/head.jsp"%>
</head>
<body class="sb-nav-fixed">
<%@ include file="../common/nav.jsp"%>
<main class="mt-5 pt-5">
<div class="container-fluid px-4">
<h1 class="mt-4">Board</h1>
<div class="card mb-4">
<div class="card-header">
<a class="btn btn-primary float-end" href="register"> <!-- <i class="fas fa-table me-1"></i> -->
<i class="fas fa-edit"></i> 글 작성
</a>
</div>
<div class="card-body">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>글번호</th>
<th>제목</th>
<th>작성자</th>
<th>조회수</th>
<th>작성일</th>
</tr>
</thead>
<tbody>
<c:forEach items="${boards}" var="board">
<tr>
<td>${board.bno}</td>
<td><a href="get?bno=${board.bno} ">${board.title}</a></td>
<td>${board.writer}</td>
<td>${board.hitCount}</td>
<td>${board.regDate}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</main>
<%@ include file="../common/footer.jsp"%>
</body>
</html>
2. 게시글 상세조회 페이지
- get.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<%@ include file="../common/head.jsp"%>
</head>
<body class="sb-nav-fixed">
<%@ include file="../common/nav.jsp"%>
<main class="mt-5 pt-5">
<div class="container-fluid px-4">
<h1 class="mt-4">Board</h1>
<div class="card mb-4">
<div class="card-body">
<form>
<div class="mb-3 mt-3">
<label for="bno" class="form-label">bno</label> <input type="text"
class="form-control" id="bno" name="bno" value="${board.bno}"
disabled>
</div>
<div class="mb-3">
<label for="title" class="form-label">title</label> <input
type="text" class="form-control" id="title" name="title"
value="${board.title}" disabled>
</div>
<div class="mb-3">
<label for="content" class="form-label">content</label>
<textarea class="form-control" id="content" name="content"
disabled>${board.content}</textarea>
</div>
<div class="mb-3">
<label for="regDate" class="form-label">regDate</label> <input
type="text" class="form-control" id="regDate" name="regDate"
value="${board.regDate}" disabled>
</div>
<div class="mb-3">
<label for="writer" class="form-label">writer</label> <input
type="text" class="form-control" id="writer" name="writer"
value="${board.writer}" disabled>
</div>
<a href="list" class="btn btn-outline-secondary">list</a> <a
href="modify?bno=${board.bno}" class="btn btn-outline-warning">modify</a>
<a href="remove?bno=${board.bno}" class="btn btn-outline-danger"
onclick="return confirm('삭제하시겠습니까?')">remove</a>
</form>
</div>
</div>
</div>
</main>
<%@ include file="../common/footer.jsp"%>
</body>
</html>
3. 게시글 수정 페이지
- controller.board.Modify.java
package controller.board;
import java.io.IOException;
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 domain.Board;
import service.BoardService;
@WebServlet("/board/modify")
public class Modify extends HttpServlet {
private BoardService boardService = BoardService.getInstance();
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Long bno = Long.parseLong(req.getParameter("bno"));
req.setAttribute("board", boardService.get(bno));
req.getRequestDispatcher("/WEB-INF/jsp/board/modify.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String title = req.getParameter("title");
String content = req.getParameter("content");
String bno = req.getParameter("bno");
Board board = new Board(Long.parseLong(bno), title, content, null);
boardService.modify(board);
resp.sendRedirect("list");
}
}
- service.BoardService.java
// 글 수정
public void modify(Board board) {
boardDao.modify(board);
}
- dao.BoardDao.java
public void modify(Board board) {
try {
Connection conn = DBConn.getConnection();
// 문장 생성
String sql = "UPDATE TBL_BOARD SET\r\n" +
"TITLE = ?,\r\n" +
"CONTENT = ?,\r\n" +
"REGDATE = SYSDATE\r\n" +
"WHERE BNO = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
// 파라미터 바인딩
pstmt.setString(1, board.getTitle());
pstmt.setString(2, board.getContent());
pstmt.setLong(3, board.getBno());
// 문장 실행(반영)
pstmt.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
- modify.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<%@ include file="../common/head.jsp"%>
</head>
<body class="sb-nav-fixed">
<%@ include file="../common/nav.jsp"%>
<main class="mt-5 pt-5">
<div class="container-fluid px-4">
<h1 class="mt-4">Board</h1>
<div class="card mb-4">
<div class="card-body">
<form method="post">
<div class="mb-3 mt-3">
<label for="bno" class="form-label">bno</label> <input type="text"
class="form-control" id="bno" name="bno" value="${board.bno}"
readonly>
</div>
<div class="mb-3">
<label for="title" class="form-label">title</label> <input
type="text" class="form-control" id="title" name="title"
value="${board.title}">
</div>
<div class="mb-3">
<label for="content" class="form-label">content</label>
<textarea class="form-control" id="content" name="content">${board.content}</textarea>
</div>
<div class="mb-3">
<label for="regDate" class="form-label">regDate</label> <input
type="text" class="form-control" id="regDate" name="regDate"
value="${board.regDate}" disabled>
</div>
<div class="mb-3">
<label for="writer" class="form-label">writer</label> <input
type="text" class="form-control" id="writer" name="writer"
value="${board.writer}" disabled>
</div>
<a href="list" class="btn btn-outline-secondary">list</a>
<button class="btn btn-outline-warning">modify</button>
</form>
</div>
</div>
</div>
</main>
<%@ include file="../common/footer.jsp"%>
</body>
</html>