위로 아래

전체

 

Controller

controller.BoardController

더보기
package controller;

import java.io.IOException;

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 bean.BoardDTO;

/**
 * Servlet implementation class BoardController
 */
@WebServlet("/jb")
public class BoardController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BoardController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String command = null;
		String page = null;
		if(request.getParameter("command")==null)
			command = "list";
		else
			command = request.getParameter("command");
		
		switch(command) {
			case "list" : {
				page = "action/BoardListAction.jsp";
				break;
			}
			case "writeForm" : {
				page = "view/BoardWriteForm.jsp";
				break;
			}
			case "writeAction" : {
				page = "action/BoardWriteAction.jsp";
				break;
			}
			case "content" : {
				page = "action/BoardContentAction.jsp";
				break;
			}
			case "update" : {
				page = "action/BoardUpdateAction.jsp";
				break;
			}
			case "updateProc" : {
				page = "action/BoardUpdateProc.jsp";
				break;
			}
			case "delete" : {
				page = "action/BoardDeleteAction.jsp";
				break;
			}
			case "reply" : {
				BoardDTO dto = new BoardDTO();
				dto.setBno(Integer.parseInt(request.getParameter("bno")));
				dto.setBref(Integer.parseInt(request.getParameter("bref")));
				dto.setBstep(Integer.parseInt(request.getParameter("bstep")));
				dto.setBlevel(Integer.parseInt(request.getParameter("blevel")));
				dto.setSubject(request.getParameter("subject"));
				request.setAttribute("dto", dto);
				page = "view/BoardWriteForm.jsp";
				break;
			}
			
			default : {
				page = "view/Error.jsp";
				break;
			}
		}
		
		RequestDispatcher dp = request.getRequestDispatcher(page);
		dp.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

 

 

 

MODEL

bean.BoardDAO

더보기
package bean;
import java.sql.*;
import java.util.*;

public class BoardDAO {
	private static BoardDAO dao = null;
	
	private BoardDAO () {};
	
	public static BoardDAO getInstance(){
		if(dao==null)
			dao = new BoardDAO();
		return dao;
	}
	
	public int BoardWrite (BoardDTO dto) {
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		int r = 0;
		conn = DBConnectionManager.getInstance().getConnection();
		
		try {
			
			int newBno = 0;
			String sql = "SELECT IFNULL(MAX(bno),0)+1 AS bno FROM board";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			if(rs.next())
				newBno = rs.getInt("bno");
			
			pstmt.close();
			rs.close();
			
			
			sql = "INSERT INTO board "
					+ "(bno, bref, bstep, blevel, "
					+ "subject, content, writer, regdate, "
					+ "ip, passwd, readcount) "
					+ "VALUES(?,?,?,?,?,?,?,SYSDATE(),?,?,?)";
			pstmt = conn.prepareStatement(sql);
			
			pstmt.setInt(1, newBno);
			
			if(dto.getBno()!=0) {
				pstmt.setInt(2, dto.getBref());
				dto.setBstep(dto.getBstep()+1);
				dto.setBlevel(dto.getBlevel()+1);
			} else {
				pstmt.setInt(2, newBno);
			}
			
			pstmt.setInt(3, dto.getBstep());
			pstmt.setInt(4, dto.getBlevel());
			pstmt.setString(5, dto.getSubject());
			pstmt.setString(6, dto.getContent());
			pstmt.setString(7, dto.getWriter());
			pstmt.setString(8, dto.getIp());
			pstmt.setString(9, dto.getPasswd());
			pstmt.setInt(10, dto.getReadcount());
			
			r = pstmt.executeUpdate();
			
		} catch(SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(conn!=null) conn.close();
				if(pstmt!=null) pstmt.close();
				if(rs!=null) rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return r;
		
	}
	
	public List<BoardDTO> getArticles() {
		List<BoardDTO> articles = new ArrayList<>();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			String sql = "SELECT ROW_NUMBER() "
					+ "OVER(ORDER BY bref DESC, bno, bstep) AS rn, "
					+ "bno, bref, bstep, blevel, readcount, "
					+ "subject, content, writer, regdate, ip, passwd "
					+ "FROM board";
			conn = DBConnectionManager.getInstance().getConnection();
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			
			while(rs.next()) {
				BoardDTO dto = new BoardDTO();
				dto.setBno(rs.getInt("bno"));
				dto.setBref(rs.getInt("bref"));
				dto.setBstep(rs.getInt("bstep"));
				dto.setBlevel(rs.getInt("blevel"));
				dto.setReadcount(rs.getInt("readcount"));
				dto.setSubject(rs.getString("subject"));
				dto.setWriter(rs.getString("writer"));
				dto.setRegdate(rs.getString("regdate"));
				dto.setIp(rs.getString("ip"));
				dto.setPasswd(rs.getString("passwd"));
				articles.add(dto);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(conn != null) conn.close();
				if(pstmt != null) pstmt.close();
				if(rs != null) rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return articles;
	}
	
	public BoardDTO getArticle(int bno) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		int r = 0;
		BoardDTO dto = new BoardDTO();
		
		try {
			String sql = "SELECT bno, bref, bstep, blevel, readcount, "
					+ "subject, content, writer, regdate, ip, passwd "
					+ "FROM board WHERE bno = ?";
			conn = DBConnectionManager.getInstance().getConnection();
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, bno);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				dto.setBno(rs.getInt("bno"));
				dto.setBref(rs.getInt("bref"));
				dto.setBstep(rs.getInt("bstep"));
				dto.setBlevel(rs.getInt("blevel"));
				dto.setReadcount(rs.getInt("readcount"));
				dto.setSubject(rs.getString("subject"));
				dto.setWriter(rs.getString("writer"));
				dto.setContent(rs.getString("content"));
				dto.setRegdate(rs.getString("regdate"));
				dto.setIp(rs.getString("ip"));
				dto.setPasswd(rs.getString("passwd"));
			}
			pstmt.close();
			rs.close();
			
			if(dto.getBno()!=0 && dto!=null) {
				sql = "UPDATE board SET readcount=readcount+1 "
						+ "WHERE bno =?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setInt(1, bno);
				r  = pstmt.executeUpdate();
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(conn != null) conn.close();
				if(pstmt != null) pstmt.close();
				if(rs != null) rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return dto;
	}
	
	public void updateArticle(BoardDTO dto) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		int r = 0;
		
		try {
			String sql = "UPDATE board SET "
					+ "subject=?,writer=?,content=?,passwd=? "
					+ "WHERE bno=?";
			conn = DBConnectionManager.getInstance().getConnection();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, dto.getSubject());
			pstmt.setString(2, dto.getWriter());
			pstmt.setString(3, dto.getContent());
			pstmt.setString(4, dto.getPasswd());
			pstmt.setInt(5, dto.getBno());
			r = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(conn != null) conn.close();
				if(pstmt != null) pstmt.close();
				if(rs != null) rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	public void deleteArticle(int bno) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		int r = 0;
		
		try {
			conn = DBConnectionManager.getInstance().getConnection();
			String sql = "DELETE FROM board WHERE bno=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, bno);
			r = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(conn != null) conn.close();
				if(pstmt != null) pstmt.close();
				if(rs != null) rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}
}

 

BoardDTO

더보기
package bean;

public class BoardDTO {
	private int rn;
	private int bno;
	private int bref;
	private int bstep;
	private int blevel;
	private int readcount;
	private String subject;
	private String content;
	private String writer;
	private String regdate;
	private String ip;
	private String passwd;
	
	public int getRn() {
		return rn;
	}
	public void setRn(int rn) {
		this.rn = rn;
	}
	
	public int getBno() {
		return bno;
	}
	public void setBno(int bno) {
		this.bno = bno;
	}
	
	public int getBref() {
		return bref;
	}
	public void setBref(int bref) {
		this.bref = bref;
	}
	
	public int getBstep() {
		return bstep;
	}
	public void setBstep(int bstep) {
		this.bstep = bstep;
	}
	
	public int getBlevel() {
		return blevel;
	}
	public void setBlevel(int blevel) {
		this.blevel = blevel;
	}
	
	public int getReadcount() {
		return readcount;
	}
	public void setReadcount(int readcount) {
		this.readcount = readcount;
	}
	
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	
	public String getRegdate() {
		return regdate;
	}
	public void setRegdate(String regdate) {
		this.regdate = regdate;
	}
	
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	
	public String getPasswd() {
		return passwd;
	}
	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}
	
}

 

bean.DBConnectionManager

더보기
package bean;

import java.sql.*;

public class DBConnectionManager {
	private Connection conn;
	private String url = "jdbc:mysql://localhost/board";
	private String user = "root";
	private String pawd = "70657065";
	private static DBConnectionManager dbmgt = null;
	
	public static DBConnectionManager getInstance () {
		if(dbmgt == null)
			dbmgt = new DBConnectionManager();
		return dbmgt;
	}
	
	public DBConnectionManager() {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public Connection getConnection() {
		try{
			conn = DriverManager.getConnection(url,user,pawd);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
}

 

 

 

VIEW

view/BoardContent.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${dto.subject}</title>
<link rel="stylesheet" type="text/css" href="css/Form.css">
<script src="jquery/jquery-3.7.0.min.js"></script>
<script type="text/javascript">
	$().ready(function(){
		let f = $("form[name=form1]");
		$("#re").on("click",function(){
			if(checkpw()){
				f.attr("action","jb?command=update");
				f.submit();
			}
		})
		$("#de").on("click",function(){
			if(checkpw()){
				if(confirm("정말 삭제하시겠습니까?")){
					f.attr("action","jb?command=delete");
					f.submit();					
				}
			}
		})
		$("#reply").on("click",function(){
			f.attr("action","jb?command=reply");
			f.submit();
		})
	})
	
	function checkpw(){
		let user_passwd = prompt("비밀번호를 입력하시오.");
		let com_passwd = ${dto.passwd}; 
		if(user_passwd == com_passwd) {
			return true;
		} else {
			alert("비밀번호가 틀렸습니다.");
			return false;
		}
	}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<table>
	<tr><td colspan="2"><h3>${dto.subject}</h3></td></tr>
	<tr>
		<th>작성자</th>
	<td><input type="text" name="writer" title="작성자" value="${dto.writer}" readonly="readonly"></td>
	</tr>
	<tr>
		<th>글 내용</th>
		<td><textarea name="content" title="글내용" readonly="readonly">${dto.content}</textarea></td>
	</tr>
	<tr>
		<th>비밀번호</th>
		<td><input type="password" name="passwd" readonly="readonly" title="비밀번호" value = "${dto.passwd}"></td>
	</tr>
	<tr>
		<td colspan="2">
			<input class="btn" type="button" value="글 수정" id="re">
			<input class="btn" type="button" value="글 삭제" id="de">
			<input class="btn" type="button" value="답글" id="reply">
			<input class="btn" type="button" value="글 목록" onclick="location.href='jb?command=list'">
		</td>
	</tr>
</table>
<input type="hidden" name="bno" value="${dto.bno}">
<input type="hidden" name="bref" value="${dto.bref}">
<input type="hidden" name="bstep" value="${dto.bstep}">
<input type="hidden" name="blevel" value="${dto.blevel}">
<input type="hidden" name="subject" value="${dto.subject}">
</form>
</body>
</html>

 

view/BoardList.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="fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>글 목록</title>
<link rel="stylesheet" type="text/css" href="css/List.css">
</head>
<body>
<div id="button">
	<button type="button" onclick="location.href='jb?command=writeForm'">글쓰기</button>
</div>
<div class="clear"></div>
<table>
	<tr>
		<td colspan="6"> <h3>게시판 (전체 글 개수 : <c:out value="${total}"/>)</h3></td>
	</tr>
	<tr>
		<th>순서</th>
		<th>제목</th>
		<th>작성자</th>
		<th>조회수</th>
		<th>작성일</th>
		<th>IP</th>
	</tr>
	<c:choose>
		<c:when test = "${fn:length(articles)==0 }">
			<tr>
				<td colspan="6">게시글이 없습니다.</td>
			</tr>
		</c:when>
		<c:when test = "${fn:length(articles)>0 }">
			<c:forEach var="x" items="${articles}">
				<tr>
					<td>${x.bno}</td>
					<td>
						<c:choose>
							<c:when test="${x.blevel==0}">
								
							</c:when>
							<c:when test="${x.blevel>0}">
								<span>ㄴ</span>
							</c:when>
						</c:choose>
						<a href="jb?command=content&bno=${x.bno}">${x.subject}</a>
					</td>
					<td>${x.writer}</td>
					<td>${x.readcount}</td>
					<td>${x.regdate}</td>
					<td>${x.ip}</td>
				<tr>
			</c:forEach>
		</c:when>
	</c:choose>
</table>
</body>
</html>

 

view/BoardUpdate.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="fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>글 작성</title>
<link rel="stylesheet" type="text/css" href="css/Form.css">
<script src="jquery/jquery-3.7.0.min.js"></script>
<script type="text/javascript">
	$().ready(function(){
		$("#submit11").on("click",function(){
			if(validate()){
				$("form[name=form1]").submit();
			}
		})
	})
	function validate(){
		let flen = $("form[name=form1] .chk").length;
		for(i=0;i<flen;i++){
			if($(".chk").eq(i).val()=="" || 
					$(".chk").eq(i).val()==null || 
					$(".chk").eq(i).val().trim()==""){
				alert($(".chk").eq(i).attr("title") + "은 꼭 입력해주세요.");
				$(".chk").focus();
				return false;
			}
		}
		return true;
	}
</script>
</head>
<body>
<form name="form1" method="post" action="jb?command=updateProc">
<table>
	<tr><td colspan="2"><h3>게시글 수정</h3></td></tr>
	<tr>
		<th>제목</th>
		<td><input type="text" name="subject" class="chk" value="${article.subject}" title="제목"></td>
		
	</tr>
	<tr>
		<th>작성자</th>
		<td><input type="text" name="writer" class="chk" value="${article.writer}" title="작성자"></td>
	</tr>
	<tr>
		<th>글 내용</th>
		<td><textarea name="content" class="chk" title="글내용">${article.content}</textarea></td>
	</tr>
	<tr>
		<th>비밀번호</th>
		<td><input type="password" name="passwd" class="chk" value="${article.passwd}" title="비밀번호"></td>
	</tr>
	<tr>
		<td colspan="2">
			<input class="btn" type="button" value="글 저장" id="submit11">
			<input class="btn" type="button" value="글 목록" onclick="location.href='jb?command=list'">
		</td>
	</tr>
</table>
<input type="hidden" name="bno" value="${article.bno}">
<input type="hidden" name="bref" value="${article.bref}">
<input type="hidden" name="bstep" value="${article.bstep}">
<input type="hidden" name="blevel" value="${article.blevel}">
</form>
</body>
</html>

 

view/BoardWriteForm.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="fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>글 작성</title>
<link rel="stylesheet" type="text/css" href="css/Form.css">
<script src="jquery/jquery-3.7.0.min.js"></script>
<script type="text/javascript">
	$().ready(function(){
		$("#submit11").on("click",function(){
			if(validate()){
				$("form[name=form1]").submit();
			}
		})
	})
	function validate(){
		let flen = $("form[name=form1] .chk").length;
		for(i=0;i<flen;i++){
			if($(".chk").eq(i).val()=="" || 
					$(".chk").eq(i).val()==null || 
					$(".chk").eq(i).val().trim()==""){
				alert($(".chk").eq(i).attr("title") + "은 꼭 입력해주세요.");
				$(".chk").focus();
				return false;
			}
		}
		return true;
	}
</script>
</head>
<body>
<form name="form1" method="post" action="jb?command=writeAction">
<table>
	<tr><td colspan="2"><h3>게시글 쓰기</h3></td></tr>
	<tr>
		<th>제목${dto.subject}</th>
		<c:choose>
			<c:when test="${dto == null}">
				<td><input type="text" name="subject" class="chk" title="제목"></td>
			</c:when>
			<c:when test="${dto.bno > 0}">
				<td><input type="text" name="subject" class="chk" title="제목" value="[답글] ${dto.subject}"></td>
			</c:when>
		</c:choose>
	</tr>
	<tr>
		<th>작성자</th>
		<td><input type="text" name="writer" class="chk" title="작성자"></td>
	</tr>
	<tr>
		<th>글 내용</th>
		<td><textarea name="content" class="chk" title="글내용"></textarea></td>
	</tr>
	<tr>
		<th>비밀번호</th>
		<td><input type="password" name="passwd" class="chk" title="비밀번호"></td>
	</tr>
	<tr>
		<td colspan="2">
			<input class="btn" type="button" value="글 저장" id="submit11">
			<input class="btn" type="button" value="글 목록" onclick="location.href='jb?command=list'">
		</td>
	</tr>
</table>
<input type="hidden" name="bno" value="${dto.bno}">
<input type="hidden" name="bref" value="${dto.bref}">
<input type="hidden" name="bstep" value="${dto.bstep}">
<input type="hidden" name="blevel" value="${dto.blevel}">
</form>
</body>
</html>

 

view/Error.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>에러</title>
</head>
<body>
<h3> 요청하신 페이지가 잘못되었습니다. </h3>
</body>
</html>

 

css/Form.css

더보기
@charset "UTF-8";

* {margin:0; padding:0;}

body{ width:100%; background-color: #f6f6ee;}
table {
	width:70%;
	margin: 0 auto;
	padding:10px;
	border-radius:25px;
}

table th {
	border : 1px solid balck;
}

table tr {text-align:center;}

table th {
	text-align:center;
	background-color : #ffffff;
	border-radius:10px;
}

input {width:90%; padding:3px;}

textarea {
	width:90%; height:300px; padding:3px;
	resize: none;	
}

.btn {width:100px; margin-top:5px; margin-bottom:10px;}

h3 {margin:5px 5px 10px 5px;}

 

css/List.css

더보기
@charset "UTF-8";

	* {margin : 0; padding : 0;}
	body{ width:100%; background-color: #f6f6ee;}
	table {
		border-collapse:collapse;
		width : 70%;
		margin : 0 auto;
		padding:10px;
		border-radius: 25px;
	}
	table td, th {
		border:1px solid #eeeeee;
		border-collapse: collapse;
		background-color: #ffffff;
		padding:6px 10px 6px 10px;
		font-weight: 300;
		
	}
	th {padding:5px; font-weight: bold;}
	#button {
		float : right;
		margin-top : 20px;
		margin-right : 15%;
		margin-bottom : 5px;
		padding : 3px;
	}
	.clear {clear: both;}
	h3 {text-align : center; padding : 5px;}
	a {text-decoration: none; color:black; font-style: none;}
	a:hover {text-decoration: none; color:black; font-style: none;}
	a:visited {text-decoration: none; color:black; font-style: none;}
	a:active {text-decoration: none; color:black; font-style: none;}

 

 

 

 

BIZ (비즈니스 로직)

action/BoardContentAction.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "bean.BoardDTO" %>
<%@ page import = "bean.BoardDAO" %>

<% 
BoardDTO dto = new BoardDTO();
BoardDAO dao = BoardDAO.getInstance();

int bno = Integer.parseInt(request.getParameter("bno"));

dto = dao.getArticle(bno);

request.setAttribute("dto", dto);

RequestDispatcher dp = request.getRequestDispatcher("../view/BoardContent.jsp");
dp.forward(request, response);

%>

 

action/BoardDeleteAction.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "bean.BoardDTO" %>
<%@ page import = "bean.BoardDAO" %>

<%
BoardDTO dto = new BoardDTO();
dto.setBno(Integer.parseInt(request.getParameter("bno")));

int bno = dto.getBno();

BoardDAO dao = BoardDAO.getInstance();

dao.deleteArticle(bno);

response.sendRedirect("jb?command=list");
%>

 

action/BoardListAction.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "bean.BoardDTO" %>
<%@ page import = "bean.BoardDAO" %>
<%@ page import = "java.util.List" %>

<%
BoardDTO dto = new BoardDTO();
BoardDAO dao = BoardDAO.getInstance();
List<BoardDTO> articles = dao.getArticles();

request.setAttribute("articles", articles);
request.setAttribute("total", articles.size());

RequestDispatcher dp = request.getRequestDispatcher("../view/BoardList.jsp");
dp.forward(request, response);
%>

 

action/BoardUpdateAction.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="bean.BoardDAO" %>
<%@ page import="bean.BoardDTO" %>

<%
	int bno = Integer.parseInt(request.getParameter("bno"));
	
	BoardDAO dao = BoardDAO.getInstance();
	
	BoardDTO article = dao.getArticle(bno);
	
	request.setAttribute("article", article);
	
 	RequestDispatcher dp = request.getRequestDispatcher("../view/BoardUpdate.jsp");
	dp.forward(request, response);
%>

 

action/BoardUpdateProc.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "bean.BoardDTO" %>
<%@ page import = "bean.BoardDAO" %>

<%
BoardDTO dto = new BoardDTO();

dto.setBno(Integer.parseInt(request.getParameter("bno")));
dto.setSubject(request.getParameter("subject"));
dto.setWriter(request.getParameter("writer"));
dto.setContent(request.getParameter("content"));
dto.setPasswd(request.getParameter("passwd"));
dto.setIp(request.getRemoteAddr());

BoardDAO dao = BoardDAO.getInstance();

dao.updateArticle(dto);

response.sendRedirect("jb?command=list");
%>

 

action/BoardWriteAction.jsp

더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.sql.*" %>
<%@ page import = "bean.BoardDTO" %>
<%@ page import = "bean.BoardDAO" %>

<%
	String subject = request.getParameter("subject");
	String writer = request.getParameter("writer");
	String content = request.getParameter("content");
	String passwd = request.getParameter("passwd");

	BoardDTO dto = new BoardDTO();
	
	if(request.getParameter("bno")!="0" && request.getParameter("bno").length()!=0
			|| request.getParameter("bno")!=null && request.getParameter("bno").length()!=0){
		dto.setBno(Integer.parseInt(request.getParameter("bno")));
		dto.setBref(Integer.parseInt(request.getParameter("bref")));
		dto.setBstep(Integer.parseInt(request.getParameter("bstep")));
		dto.setBlevel(Integer.parseInt(request.getParameter("blevel")));
	}

	
	dto.setSubject(subject);
	dto.setWriter(writer);
	dto.setContent(content);
	dto.setPasswd(passwd);
	dto.setIp(request.getRemoteAddr());
	
	BoardDAO dao = BoardDAO.getInstance();
	dao.BoardWrite(dto);
	
	response.sendRedirect("jb?command=list");
	
	
%>

 

 

 

완성 모습

글 목록

 

글 작성

 

글 보기

 

글 수정

 

답글 작성