본문 바로가기
Web & Mobile/JSP

Lecture 56 - JSP(14) MVC Model2 기반 게시판(1)

by Bennyziio 2019. 6. 4.
반응형

MVC 패턴(Model2)으로 게시판을 생성해 보자!!
게시판 만들때 model1 우선 돌아가는거 확인하고 model2 진행하는데 선행되야할 조건은 
jdbc드라이버 -> context -> 클래스파일 -> jsp파일 순으로 진행해야 에러가 안남

위와 같이 설정해 준다. 그리고 board_list1이 동작하는지 확인한다(쓰기, 수정, 삭제) 이후 이상없으면 model1을 통째로 복사해서 model2라고 만들어준다.

Model2Ex01.src에 servlet이란 패키지를 만들어주고 안에 servlet을 다음 그림과 같이 생성한다.

Constructors from superclass는 체크 해제 해주도록 하자

model2라는 패키지를 만든다 -> Action을 만들고 -> ListAction, WriteAction, WriteOkAction 순으로 만들되 3가지에는 Action을 implement시켜준다

ControllerEx01에 아래와 같이 list, write, write_ok에 맞게끔 추가해준다.

if(action == null || action.equals("") || action.equals("list")) {
	baction = new ListAction();
	baction.execute(request, response);
				
	url = "/model2/board_list1.jsp";
}
실행 방법

* jsp 직접 요청(X)

Controller?action=write

Controller?action=write_ok

Controller?action=list

위 방법대로 해서 http://localhost:8080/Model2Ex01/controller?action=write 와 같이 주소를 입력해주면 아래와 같이 된다.

의도한 write 페이지가 출력이 되지만 디자인이 깨진다는 문제가 있다.
디자인을 수정해주기 위해 model2.board_write1.jsp로 간다

<link rel="stylesheet" type="text/css" href="../css/board_write.css">

href="./css/board_write.css">으로 수정해줘야한다.

<link rel="stylesheet" type="text/css" href="./css/board_write.css">

board_write1을 아래와 같이 수정한다.

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			//alert('click');
			if(document.frm.info.checked == false) {
				alert('동의하셔야 합니다.');
				return;
			}
			
			if(document.frm.writer.value.trim() == "") {
				alert('이름을 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.subject.value.trim() == "") {
				alert('제목을 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="write_ok" />
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="" class="board_view_input" /></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				<tr>
					<th>내용</th>
					<td colspan="3"><textarea name="content" class="board_editor_area"></textarea></td>
				</tr>
				<tr>
					<th>이메일</th>
					<td colspan="3"><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></td>
				</tr>
				</table>
				
				<table>
				<tr>
					<br />
					<td style="text-align:left;border:1px solid #e0e0e0;background-color:f9f9f9;padding:5px">
						<div style="padding-top:7px;padding-bottom:5px;font-weight:bold;padding-left:7px;font-family: Gulim,Tahoma,verdana;">※ 개인정보 수집 및 이용에 관한 안내</div>
						<div style="padding-left:10px;">
							<div style="width:97%;height:95px;font-size:11px;letter-spacing: -0.1em;border:1px solid #c5c5c5;background-color:#fff;padding-left:14px;padding-top:7px;">
								1. 수집 개인정보 항목 : 회사명, 담당자명, 메일 주소, 전화번호, 홈페이지 주소, 팩스번호, 주소 <br />
								2. 개인정보의 수집 및 이용목적 : 제휴신청에 따른 본인확인 및 원활한 의사소통 경로 확보 <br />
								3. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다. <br />
								4. 그 밖의 사항은 개인정보취급방침을 준수합니다.
							</div>
						</div>
						<div style="padding-top:7px;padding-left:5px;padding-bottom:7px;font-family: Gulim,Tahoma,verdana;">
							<input type="checkbox" name="info" value="1" class="input_radio"> 개인정보 수집 및 이용에 대해 동의합니다.
						</div>
					</td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./controller?action=list'">목록</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">등록</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

글쓰기를 요청받으면 controller가 요청을 받아서 writeAction과  board_write1.jsp로 보내고 이를 받아서 jsp에서 로직을 수행하고 다시 controller로 write_ok를 송출하면 이걸 다시 controller는 writeOkAction으로 송출한다. WriteOkAction에서 DAO로 인서트해서 요청하고 이때 setAttribute로 flag값을 board_write1_ok.jsp로 보낸다. board_write1_ok.jsp에서는 받은 flag값을 로직수행하고 흐름상 경로인 list로 보내주는데 이를 ./controller?action=list로 보낸다.

jsp는 디자인 요소만 남아있고 action에서 모든 로직을 처리한다.

Model2Ex01.servlet.ControllerEx01

package servlet;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

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 model2.Action;
import model2.DeleteAction;
import model2.DeleteOkAction;
import model2.ListAction;
import model2.ModifyAction;
import model2.ModifyOkAction;
import model2.ViewAction;
import model2.WriteAction;
import model2.WriteOkAction;

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

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			request.setCharacterEncoding("utf-8");
			
			String action = request.getParameter("action");
			
			String url = "/model2/error.jsp";
			Action baction = null;
			if(action == null || action.equals("") || action.equals("list")) {
				baction = new ListAction();
				baction.execute(request, response);
				
				url = "/model2/board_list1.jsp";
			} else if(action.equals("view")) {
				baction = new ViewAction();
				baction.execute(request, response);
				
				url = "/model2/board_view1.jsp";
			} else if(action.equals("write")) {
				baction = new WriteAction();
				baction.execute(request, response);
				
				url = "/model2/board_write1.jsp";
			} else if(action.equals("write_ok")) {
				baction = new WriteOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_write1_ok.jsp";
			} else if(action.equals("modify")) {
				baction = new ModifyAction();
				baction.execute(request, response);
				
				url = "/model2/board_modify1.jsp";
			} else if(action.equals("modify_ok")) {
				baction = new ModifyOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_modify1_ok.jsp";
			} else if(action.equals("delete")) {
				baction = new DeleteAction();
				baction.execute(request, response);
				
				url = "/model2/board_delete1.jsp";
			} else if(action.equals("delete_ok")) {
				baction = new DeleteOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_delete1_ok.jsp";
			}
			
			RequestDispatcher dispatcher = request.getRequestDispatcher(url);
			dispatcher.forward(request, response);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

Model2Ex01.model1.BoardDAO

package model1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

// 각 페이지당 할일
public class BoardDAO {
	// jsp 처리할 일을 메소드화
	// jsp 페이지와 1 : 1
	private DataSource datasource = null;
	
	public BoardDAO() {
		// 데이터 소스를 얻어 냄
		try {
			Context initCtx = new InitialContext();
			Context envCtx = (Context)initCtx.lookup("java:comp/env");
			this.datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		} catch (NamingException e) {
			System.out.println("[에러] : " + e.getMessage());
		}
	}
	
	public void boardWrite() {
		// 할 일 없음
	}		
	public int boardWriteOk(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		int flag = 1;
		
		try {
			conn = datasource.getConnection();		
			
			String sql = "insert into board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate)";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSubject());
			pstmt.setString(2, to.getWriter());
			pstmt.setString(3, to.getMail());
			pstmt.setString(4, to.getPassword());
			pstmt.setString(5, to.getContent());
			pstmt.setString(6, to.getWip());
		
			int result = pstmt.executeUpdate();
			if(result == 1) {
				flag = 0;
			}
			
		} catch(SQLException e) {
			System.out.println("[에러] " + e.getMessage());
ll) try {rs.close();} catch(SQLException e) {};
			if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
			if(conn != null) try {conn.close();} catch(SQLException e) {};
		}
		return to;
	}
	public BoardTO boardModify(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			conn = datasource.getConnection();

			String sql = "select subject, writer, mail, content from board1 where seq=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			
			rs = pstmt.executeQuery();
			if(rs.next()) {
				to.setSubject(rs.getString("subject"));
				to.setWriter(rs.getString("writer"));
				to.setMail(rs.getString("mail"));
				to.setContent(rs.getString("content") == null ? "" : rs.getString("content"));
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(rs != null) try { rs.close(); } catch(SQLException e) {}
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}
		
		return to;
	}
	public int boardModifyOk(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		int flag = 2;
		
		try {
			conn = datasource.getConnection();
			
			String sql = "update board1 set subject=?, mail=?, content=? where seq=? and password=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSubject());
			pstmt.setString(2, to.getMail());
			pstmt.setString(3, to.getContent());
			pstmt.setString(4, to.getSeq());
			pstmt.setString(5, to.getPassword());
			
			int result = pstmt.executeUpdate();
			if(result == 0) {
				flag = 1;
			} else if(result == 1) {
				flag = 0;
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}

		return flag;
	}
	public BoardTO boardDelete(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			conn = datasource.getConnection();

			String sql = "select subject, writer from board1 where seq=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			
			rs = pstmt.executeQuery();
			if(rs.next()) {
				to.setSubject(rs.getString("subject"));
				to.setWriter(rs.getString("writer"));
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(rs != null) try { rs.close(); } catch(SQLException e) {}
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}
		
		return to;
	}
	public int boardDeleteOk(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		int flag = 2;
		
		try {
			conn = datasource.getConnection();
			
			String sql = "delete from board1 where seq = ? and password = ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			pstmt.setString(2, to.getPassword());
		
			int result = pstmt.executeUpdate();
			if(result == 1) {
				// 정상
				flag = 0;
			} else if (result == 0) {
				// 비밀번호 오류
				flag = 1;
			}
			
		} catch(SQLException e) {
			System.out.println("[에러] " + e.getMessage());
		} finally {
			if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
			if(conn != null) try {conn.close();} catch(SQLException e) {};
		}
		return flag;
	}
}

Model2Ex01.model1.BoardTO

package model1;
// 데이터
public class BoardTO {
	// data - table / select(list + view)
	private String seq;
	private String subject;
	private String writer;
	private String mail;
	private String[] email;
	private String password;
	private String content;
	private String hit;
	private String wip;
	private String wdate;
	private int wgap;
	
	public String getSeq() {
		return seq;
	}
	public void setSeq(String seq) {
		this.seq = seq;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getHit() {
		return hit;
	}
	public void setHit(String hit) {
		this.hit = hit;
	}
	public String getWip() {
		return wip;
	}
	public void setWip(String wip) {
		this.wip = wip;
	}
	public String getWdate() {
		return wdate;
	}
	public void setWdate(String wdate) {
		this.wdate = wdate;
	}
	public int getWgap() {
		return wgap;
	}
	public void setWgap(int wgap) {
		this.wgap = wgap;
	}
}

Model2Ex01.model2.Action

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public interface Action {
	public abstract void execute(HttpServletRequest request, HttpServletResponse response);
}

Model2Ex01.model2.WriteAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WriteAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		System.out.println("WriteAction 호출");
	}

}

Model2Ex01.model2.WriteOkAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class WriteOkAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		//request.setCharacterEncoding("utf-8");

		String subject = request.getParameter("subject");
		String writer = request.getParameter("writer");
		String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
		String password = request.getParameter("password");
		String content = request.getParameter("content");

		String wip = request.getRemoteAddr();

		BoardTO to = new BoardTO();
		to.setSubject(subject);
		to.setWriter(writer);
		to.setMail(mail);
		to.setPassword(password);
		to.setContent(content);
		to.setWip(wip);
		
		BoardDAO dao = new BoardDAO();
		int flag = dao.boardWriteOk(to);
		
		request.setAttribute("flag", flag);
	}

}

Model2Ex01.model2.ListAction

package model2;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class ListAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		BoardDAO dao = new BoardDAO();
		ArrayList<BoardTO> lists = dao.boardList();
		
		request.setAttribute("list", lists);
	}

}

Model2Ex01.model2.ViewAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class ViewAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

		String seq = request.getParameter("seq");
		
		BoardTO to = new BoardTO();
		to.setSeq(seq);
		
		BoardDAO dao = new BoardDAO();
		to = dao.boardView(to);
		
		request.setAttribute("to", to);
	}

}

Model2Ex01.model2.DeleteAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class DeleteAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub		
		BoardTO to = new BoardTO();
		to.setSeq(request.getParameter("seq"));
		
		BoardDAO dao = new BoardDAO();
		//to = dao.boardView(to);
		to = dao.boardDelete(to);
		//to = dao.boardDeleteOk(to);
		
		request.setAttribute("to", to);
	}

}

Model2Ex01.model2.DeleteOkAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class DeleteOkAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

		String seq = request.getParameter("seq");
		String password = request.getParameter("password");
		
		BoardTO to = new BoardTO();
		to.setSeq(seq);
		to.setPassword(password);
		
		BoardDAO dao = new BoardDAO();
		int flag = dao.boardDeleteOk(to);
		
		request.setAttribute("flag", flag);
	}

}

Model2Ex01.model2.ModifyAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class ModifyAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		BoardTO to = new BoardTO();
		to.setSeq(request.getParameter("seq"));
		
		BoardDAO dao = new BoardDAO();
		to = dao.boardView(to);
		
		request.setAttribute("to", to);
	}

}

Model2Ex01.model2.ModifyOkAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model1.BoardDAO;
import model1.BoardTO;

public class ModifyOkAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

		String seq = request.getParameter("seq");
		String subject = request.getParameter("subject");
		String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
		String password = request.getParameter("password");
		String content = request.getParameter("content");
		String wip = request.getRemoteAddr();
		
		BoardTO to = new BoardTO();
		to.setSubject(subject);
		to.setMail(mail);
		to.setPassword(password);
		to.setContent(content);
		to.setSeq(seq);
		
		BoardDAO dao = new BoardDAO();
		
		int flag = dao.boardModifyOk(to);
		
		request.setAttribute("seq", to.getSeq());
		request.setAttribute("flag", flag);
	}

}

Model2Ex01.servlet.ControllerEx01

package servlet;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

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 model2.Action;
import model2.DeleteAction;
import model2.DeleteOkAction;
import model2.ListAction;
import model2.ModifyAction;
import model2.ModifyOkAction;
import model2.ViewAction;
import model2.WriteAction;
import model2.WriteOkAction;

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

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			request.setCharacterEncoding("utf-8");
			
			String action = request.getParameter("action");
			
			String url = "/model2/error.jsp";
			Action baction = null;
			if(action == null || action.equals("") || action.equals("list")) {
				baction = new ListAction();
				baction.execute(request, response);
				
				url = "/model2/board_list1.jsp";
			} else if(action.equals("view")) {
				baction = new ViewAction();
				baction.execute(request, response);
				
				url = "/model2/board_view1.jsp";
			} else if(action.equals("write")) {
				baction = new WriteAction();
				baction.execute(request, response);
				
				url = "/model2/board_write1.jsp";
			} else if(action.equals("write_ok")) {
				baction = new WriteOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_write1_ok.jsp";
			} else if(action.equals("modify")) {
				baction = new ModifyAction();
				baction.execute(request, response);
				
				url = "/model2/board_modify1.jsp";
			} else if(action.equals("modify_ok")) {
				baction = new ModifyOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_modify1_ok.jsp";
			} else if(action.equals("delete")) {
				baction = new DeleteAction();
				baction.execute(request, response);
				
				url = "/model2/board_delete1.jsp";
			} else if(action.equals("delete_ok")) {
				baction = new DeleteOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_delete1_ok.jsp";
			}
			
			RequestDispatcher dispatcher = request.getRequestDispatcher(url);
			dispatcher.forward(request, response);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

Model2Ex01.WebContent.model2.board_list1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!-- Java 전처리 -->
<%@ page import="java.util.ArrayList" %>
<%@ page import="model1.BoardTO" %>

<%
	ArrayList<BoardTO> lists = (ArrayList)request.getAttribute("list");
	
	int totalRecord = lists.size();
	
	StringBuffer sb = new StringBuffer();
	
	for(BoardTO to : lists) {
		String seq = to.getSeq();
		String subject = to.getSubject();
		String writer = to.getWriter();
		String wdate = to.getWdate();
		String hit = to.getHit();
		int wgap = to.getWgap();
		
		sb.append("<tr>");
		sb.append("	<td>&nbsp;</td>");
		sb.append("	<td>" + seq + "</td>");
		if(wgap == 0 ) {
			sb.append("	<td class='left'><a href='./controller?action=view&seq=" + seq + "'>" + subject + "</a>&nbsp;<img src='./images/icon_hot.gif' alt='HOT'></td>");	
		} else {
			sb.append("	<td class='left'><a href='./controller?action=view&seq=" + seq + "'>" + subject + "</a></td>");
		}
		
		sb.append("	<td>" + writer + "</td>");
		sb.append("	<td>" + wdate + "</td>");
		sb.append("	<td>" + hit + "</td>");
		sb.append("	<td>&nbsp;</td>");
		sb.append("</tr>");
	}
%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_list.css">
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<div class="contents_sub">
		<div class="board_top">
			<div class="bold">총 <span class="txt_orange"><%=totalRecord %></span>건</div>
		</div>

		<!--게시판-->
		<div class="board">
			<table>
			<tr>
				<th width="3%">&nbsp;</th>
				<th width="5%">번호</th>
				<th>제목</th>
				<th width="10%">글쓴이</th>
				<th width="17%">등록일</th>
				<th width="5%">조회</th>
				<th width="3%">&nbsp;</th>
			</tr>
			<tr>
			<!-- 시작 -->
			<%= sb %>
			<!-- 끝 -->
			</tr>
			</table>
		</div>	
		<!--//게시판-->

		<div class="align_right">
			<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='controller?action=write'">쓰기</button>
		</div>
	</div>
</div>
<!--//하단 디자인 -->

</body>
</html>

Model2Ex01.WebContent.model2.board_write1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			//alert('click');
			if(document.frm.info.checked == false) {
				alert('동의하셔야 합니다.');
				return;
			}
			
			if(document.frm.writer.value.trim() == "") {
				alert('이름을 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.subject.value.trim() == "") {
				alert('제목을 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="write_ok" />
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="" class="board_view_input" /></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				<tr>
					<th>내용</th>
					<td colspan="3"><textarea name="content" class="board_editor_area"></textarea></td>
				</tr>
				<tr>
					<th>이메일</th>
					<td colspan="3"><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></td>
				</tr>
				</table>
				
				<table>
				<tr>
					<br />
					<td style="text-align:left;border:1px solid #e0e0e0;background-color:f9f9f9;padding:5px">
						<div style="padding-top:7px;padding-bottom:5px;font-weight:bold;padding-left:7px;font-family: Gulim,Tahoma,verdana;">※ 개인정보 수집 및 이용에 관한 안내</div>
						<div style="padding-left:10px;">
							<div style="width:97%;height:95px;font-size:11px;letter-spacing: -0.1em;border:1px solid #c5c5c5;background-color:#fff;padding-left:14px;padding-top:7px;">
								1. 수집 개인정보 항목 : 회사명, 담당자명, 메일 주소, 전화번호, 홈페이지 주소, 팩스번호, 주소 <br />
								2. 개인정보의 수집 및 이용목적 : 제휴신청에 따른 본인확인 및 원활한 의사소통 경로 확보 <br />
								3. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다. <br />
								4. 그 밖의 사항은 개인정보취급방침을 준수합니다.
							</div>
						</div>
						<div style="padding-top:7px;padding-left:5px;padding-bottom:7px;font-family: Gulim,Tahoma,verdana;">
							<input type="checkbox" name="info" value="1" class="input_radio"> 개인정보 수집 및 이용에 대해 동의합니다.
						</div>
					</td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./controller?action=list'">목록</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">등록</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex01.WebContent.model2.board_write1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
	int flag = (Integer)request.getAttribute("flag");

	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글쓰기에 성공했습니다.');");
		out.println("location.href='./controller?action=list';");
	} else if(flag == 1) {
		out.println("alert('글쓰기에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

Model2Ex01.WebContent.model2.board_view1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="model1.BoardTO" %>

<%
	BoardTO to = (BoardTO)request.getAttribute("to");

	String seq = to.getSeq();	
	String subject = to.getSubject();
	String writer = to.getWriter();
	String wdate = to.getWdate();
	String hit = to.getHit();
	String content = to.getContent();
	String mail = to.getMail();
%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_view.css">
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<div class="contents_sub">
		<!--게시판-->
		<div class="board_view">
			<table>
			<tr>
				<th width="10%">제목</th>
				<td width="60%"><%= subject %></td>
				<th width="10%">등록일</th>
				<td width="20%"><%= wdate %></td>
			</tr>
			<tr>
				<th>글쓴이</th>
				<td><%= writer %><%= '(' + mail + ')' %></td>
				<th>조회</th>
				<td><%= hit %></td>
			</tr>
			<tr>
				<td colspan="4" height="200" valign="top" style="padding: 20px; line-height: 160%"><%= content %></td>
			</tr>
			</table>
		</div>

		<div class="btn_area">
			<div class="align_left">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./controller?action=list'">목록</button>
			</div>
			<div class="align_right">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./controller?action=modify&seq=<%= seq %>'">수정</button>
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./controller?action=delete&seq=<%= seq %>'">삭제</button>
				<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='./controller?action=write'">쓰기</button>
			</div>
		</div>	
		<!--//게시판-->
	</div>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex01.WebContent.model2.board_delete1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="model1.BoardTO" %>

<%
	BoardTO to = (BoardTO)request.getAttribute("to");
	
	String seq = to.getSeq();
	String subject = to.getSubject();
	String writer = to.getWriter();
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="delete_ok" />
	<input type="hidden" name="seq" value="<%=seq %>" />	<!-- delete할 때 seq를 받아오기 위해 hidden으로해서 작성 / 브라우저에서 소스보기 하면 값 확인가능 -->
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="<%= writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="<%= subject %>" class="board_view_input" readonly/></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=list'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=view&seq=<%=seq %>'">보기</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">삭제</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex01.WebContent.model2.board_delete1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
	int flag = (Integer)request.getAttribute("flag");
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 삭제에 성공했습니다.');");
		out.println("location.href='./controller?action=list';");
	} else if(flag == 1) {
		out.println("alert('비밀번호 오류입니다.');");
		out.println("history.back();");
	} else if(flag == 2) {
		out.println("alert('글 삭제에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

Model2Ex01.WebContent.model2.board_modify1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="model1.BoardTO" %>

<%
	BoardTO to = (BoardTO)request.getAttribute("to");
	
	String seq = to.getSeq();
	String subject = to.getSubject();
	String writer = to.getWriter();
	String content = to.getContent();
	String mail[] = to.getMail().split("@");
	if(mail.length == 0) {
		mail = new String[] {"", ""};
	}
	
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			if(document.frm.writer.value.trim() == "") {
				alert('이름을 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.subject.value.trim() == "") {
				alert('제목을 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="modify_ok" />
	<input type="hidden" name="seq" value="<%=seq %>" />
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="<%=subject %>" class="board_view_input" /></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				<tr>
					<th>내용</th>
					<td colspan="3"><textarea name="content" class="board_editor_area"><%=content %></textarea></td>
				</tr>
				<tr>
					<th>이메일</th>
					<td colspan="3"><input type="text" name="mail1" value="<%=mail[0] %>" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="<%=mail[1] %>" class="board_view_input_mail"/></td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=list'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=view&seq=<%=seq %> %>'">보기</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">수정</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex01.WebContent.model2.board_modify1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
	String seq = (String)request.getAttribute("seq");
	int flag = (Integer)request.getAttribute("flag");
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 수정에 성공했습니다.');");
		out.println("location.href='./controller?action=list&seq=" + seq + "';");
	} else if(flag == 1) {
		out.println("alert('비밀번호 오류입니다.');");
		out.println("history.back();");
	} else if(flag == 2) {
		out.println("alert('글 수정에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

페이지 기능있는 모델2 게시판을 만들어 보자!!

* model1 돌아가게끔 세팅
1. jdbc드라이버
2. context.xml
3. beans
4. jsp, image, css

servlet
        BoardController
model2
        Action
        ListAction
        ViewAction
        WriteAction
        WriteOkAction
        ModifyAction
        ModifyOkAction
        DeleteAction
        DeleteOkAction

jsp 수정

model1인 paging 소스가 구동되는 것을 확인 후 paging폴더 통째로 model2로 수정해서 코딩 시작

Model2Ex02.paging1.BoardDAO

package paging1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class BoardDAO {
	private DataSource dataSource = null;
	
	public BoardDAO() {
		try {
			Context initCtx = new InitialContext();
			Context envCtx = (Context)initCtx.lookup("java:comp/env");
			this.dataSource = (DataSource)envCtx.lookup("jdbc/oracle1");
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			System.out.println("[에러] : " + e.getMessage());
		}
	}
	
	public void boardWrite() {
	}
	
	public int boardWriteOk(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		int flag = 1;
		
		try {
			conn = dataSource.getConnection();
			
			String sql = "insert into board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate)";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSubject());
			pstmt.setString(2, to.getWriter());
			pstmt.setString(3, to.getMail());
			pstmt.setString(4, to.getPassword());
			pstmt.setString(5, to.getContent());
			pstmt.setString(6, to.getWip());
		
			int result = pstmt.executeUpdate();
			if(result == 1) {
				flag = 0;
			}			
		} catch(SQLException e) {
			System.out.println("[에러] " + e.getMessage());
		} finally {
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { conn.close(); } catch(SQLException e) {}
		}
		
		return flag;
	}
	
	public BoardListTO boardList(BoardListTO listTO) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		int cpage = listTO.getCpage();
		int recordPerPage = listTO.getRecordPerPage();
		int blockPerPage = listTO.getBlockPerPage();
		
		try {
			conn = dataSource.getConnection();

			String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, hit, trunc(sysdate-wdate) wgap from board1 order by seq desc";
			pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		
			rs = pstmt.executeQuery();
			
			rs.last();
			listTO.setTotalRecord(rs.getRow());
			rs.beforeFirst();
			
			listTO.setTotalPage(((listTO.getTotalRecord() - 1)/recordPerPage) + 1);
			
			int skip = (cpage - 1) * recordPerPage;
			if(skip != 0) rs.absolute(skip);
			
			ArrayList<BoardTO> boardLists = new ArrayList<>();
			
			for(int i=0 ; i<recordPerPage && rs.next() ; i++) {
				BoardTO to = new BoardTO();
				to.setSeq(rs.getString("seq"));
				to.setSubject(rs.getString("subject"));
				to.setWriter(rs.getString("writer"));
				to.setWdate(rs.getString("wdate"));
				to.setHit(rs.getString("hit"));
				to.setWgap(rs.getInt("wgap"));
				
				boardLists.add(to);
			}
			
			listTO.setBoardLists(boardLists);
			
			listTO.setStartBlock(((cpage - 1)/blockPerPage)*blockPerPage + 1);
			listTO.setEndBlock(((cpage - 1)/blockPerPage)*blockPerPage + blockPerPage);
			if(listTO.getEndBlock() >= listTO.getTotalPage()) {
				listTO.setEndBlock(listTO.getTotalPage());
			}
			
		} catch(SQLException e) {
			System.out.println("[에러] " + e.getMessage());
		} finally {
			if(rs != null) try { rs.close(); } catch(SQLException e) {}
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { conn.close(); } catch(SQLException e) {}
		}
		return listTO;
	}
	
	public BoardTO boardView(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			conn = dataSource.getConnection();

			String sql = "update board1 set hit=hit+1 where seq=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());

			pstmt.executeUpdate();
			
			sql = "select subject, writer, mail, wip, wdate, hit, content from board1 where seq=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			
			rs = pstmt.executeQuery();
			if(rs.next()) {
				to.setSubject(rs.getString("subject"));
				to.setWriter(rs.getString("writer"));
				to.setMail(rs.getString("mail").equals("@") ? "" : "(" + rs.getString("mail") + ")");
				to.setWip(rs.getString("wip"));
				to.setWdate(rs.getString("wdate"));
				to.setHit(rs.getString("hit"));
				to.setContent(rs.getString("content") == null ? "" : rs.getStr {
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(rs != null) try { rs.close(); } catch(SQLException e) {}
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}
		
		return to;
	}
    public BoardTO boardModify(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			conn = dataSource.getConnection();

			String sql = "select subject, writer, mail, content from board1 where seq=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			
			rs = pstmt.executeQuery();
			if(rs.next()) {
				to.setSubject(rs.getString("subject"));
				to.setWriter(rs.getString("writer"));
				to.setMail(rs.getString("mail"));
				to.setContent(rs.getString("content") == null ? "" : rs.getString("content"));
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(rs != null) try { rs.close(); } catch(SQLException e) {}
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}
		
		return to;
	}
	
	public int boardModifyOk(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		int flag = 2;
		
		try {
			conn = dataSource.getConnection();
			
			String sql = "update board1 set subject=?, mail=?, content=? where seq=? and password=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSubject());
			pstmt.setString(2, to.getMail());
			pstmt.setString(3, to.getContent());
			pstmt.setString(4, to.getSeq());
			pstmt.setString(5, to.getPassword());
			
			int result = pstmt.executeUpdate();
			if(result == 0) {
				flag = 1;
			} else if(result == 1) {
				flag = 0;
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}

		return flag;
	}
	
	public BoardTO boardDelete(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			conn = dataSource.getConnection();

			String sql = "select subject, writer from board1 where seq=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			
			rs = pstmt.executeQuery();
			if(rs.next()) {
				to.setSubject(rs.getString("subject"));
				to.setWriter(rs.getString("writer"));
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(rs != null) try { rs.close(); } catch(SQLException e) {}
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}
		
		return to;
	}
	
	public int boardDeleteOk(BoardTO to) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		int flag = 2;
		
		try {
			conn = dataSource.getConnection();
			
			String sql = "delete from board1 where seq=? and password=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, to.getSeq());
			pstmt.setString(2, to.getPassword());
			
			int result = pstmt.executeUpdate();
			if(result == 0) {
				flag = 1;
			} else if(result == 1) {
				flag = 0;
			}
		} catch(SQLException e) {
			System.out.println("[에러] : " + e.getMessage());
		} finally {
			if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
			if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
		}
		return flag;
	}
}

Model2Ex02.paging1.BoardListTO

package paging1;

import java.util.ArrayList;

public class BoardListTO {
	private int cpage;
	private int recordPerPage;
	private int blockPerPage;
	private int totalPage;
	private int totalRecord;
	private int startBlock;
	private int endBlock;
	
	private ArrayList<BoardTO> boardLists;

	public BoardListTO() {
		this.cpage = 1;
		this.recordPerPage = 10;
		this.blockPerPage = 5;
		this.totalPage = 1;
		this.totalRecord = 0;
	}
	
	public int getCpage() {
		return cpage;
	}

	public void setCpage(int cpage) {
		this.cpage = cpage;
	}

	public int getRecordPerPage() {
		return recordPerPage;
	}

	public void setRecordPerPage(int recordPerPage) {
		this.recordPerPage = recordPerPage;
	}

	public int getBlockPerPage() {
		return blockPerPage;
	}

	public void setBlockPerPage(int blockPerPage) {
		this.blockPerPage = blockPerPage;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public int getStartBlock() {
		return startBlock;
	}

	public void setStartBlock(int startBlock) {
		this.startBlock = startBlock;
	}

	public int getEndBlock() {
		return endBlock;
	}

	public void setEndBlock(int endBlock) {
		this.endBlock = endBlock;
	}

	public ArrayList<BoardTO> getBoardLists() {
		return boardLists;
	}

	public void setBoardLists(ArrayList<BoardTO> boardLists) {
		this.boardLists = boardLists;
	}
}

Model2Ex02.paging1.BoardTO

package paging1;

public class BoardTO {
	// data - table / select(list + view)
	private String seq;
	private String subject;
	private String writer;
	private String mail;
	private String password;
	private String content;
	private String hit;
	private String wip;
	private String wdate;
	private int wgap;
	
	public String getSeq() {
		return seq;
	}
	public void setSeq(String seq) {
		this.seq = seq;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getHit() {
		return hit;
	}
	public void setHit(String hit) {
		this.hit = hit;
	}
	public String getWip() {
		return wip;
	}
	public void setWip(String wip) {
		this.wip = wip;
	}
	public String getWdate() {
		return wdate;
	}
	public void setWdate(String wdate) {
		this.wdate = wdate;
	}
	public int getWgap() {
		return wgap;
	}
	public void setWgap(int wgap) {
		this.wgap = wgap;
	}
}

Model2Ex02.servlet.BoardController

package servlet;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

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 model2.Action;
import model2.DeleteAction;
import model2.DeleteOkAction;
import model2.ListAction;
import model2.ModifyAction;
import model2.ModifyOkAction;
import model2.ViewAction;
import model2.WriteAction;
import model2.WriteOkAction;

/**
 * Servlet implementation class BoardController
 */
@WebServlet("/controller")
public class BoardController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request, response);
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			request.setCharacterEncoding("utf-8");
			
			String action = request.getParameter("action");
			
			String url = "/model2/error.jsp";
			Action baction = null;
			if(action == null || action.equals("") || action.equals("list")) {
				baction = new ListAction();
				baction.execute(request, response);
				
				url = "/model2/board_list1.jsp";			
			} else if(action.equals("view")) {
				baction = new ViewAction();
				baction.execute(request, response);
				
				url = "/model2/board_view1.jsp";
			} else if(action.equals("write")) {
				baction = new WriteAction();
				baction.execute(request, response);
				
				url = "/model2/board_write1.jsp";
			} else if(action.equals("write_ok")) {
				baction = new WriteOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_write1_ok.jsp";
			} else if(action.equals("modify")) {
				baction = new ModifyAction();
				baction.execute(request, response);
				
				url = "/model2/board_modify1.jsp";
			} else if(action.equals("modify_ok")) {
				baction = new ModifyOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_modify1_ok.jsp";
			} else if(action.equals("delete")) {
				baction = new DeleteAction();
				baction.execute(request, response);
				
				url = "/model2/board_delete1.jsp";
			} else if(action.equals("delete_ok")) {
				baction = new DeleteOkAction();
				baction.execute(request, response);
				
				url = "/model2/board_delete1_ok.jsp";
			}
			
			RequestDispatcher dispatcher = request.getRequestDispatcher(url);
			dispatcher.forward(request, response);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Model2Ex02.model2.Action

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public interface Action {
	public abstract void execute(HttpServletRequest request, HttpServletResponse response);
}

Model2Ex02.model2.ListAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardListTO;

public class ListAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		int cpage = 1;
		if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
			cpage = Integer.parseInt(request.getParameter("cpage"));
		}
		
		BoardListTO listTO = new BoardListTO();		// 20180725
		listTO.setCpage(cpage);						// 20180725
		
		BoardDAO dao = new BoardDAO();				// 20180725
		listTO = dao.boardList(listTO);				// 20180725
		
		request.setAttribute("listTO", listTO);
	}

}

Model2Ex02.model2.WriteAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardListTO;

public class WriteAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		int cpage = 1;
		if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
			cpage = Integer.parseInt(request.getParameter("cpage"));
		}
		BoardListTO listTO = new BoardListTO();		// 20180725
		listTO.setCpage(cpage);						// 20180725
		
		BoardDAO dao = new BoardDAO();				// 20180725
		listTO = dao.boardList(listTO);				// 20180725
		
		request.setAttribute("listTO", listTO);
		System.out.println("WriteAction 호출");
	}

}

Model2Ex02.model2.WriteOkAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardTO;

public class WriteOkAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		//request.setCharacterEncoding("utf-8");

		String subject = request.getParameter("subject");
		String writer = request.getParameter("writer");
		String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
		String password = request.getParameter("password");
		String content = request.getParameter("content");

		String wip = request.getRemoteAddr();

		BoardTO to = new BoardTO();
		to.setSubject(subject);
		to.setWriter(writer);
		to.setMail(mail);
		to.setPassword(password);
		to.setContent(content);
		to.setWip(wip);
		
		BoardDAO dao = new BoardDAO();
		int flag = dao.boardWriteOk(to);
		
		request.setAttribute("flag", flag);
	}

}

Model2Ex02.model2.ViewAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardListTO;
import paging1.BoardTO;

public class ViewAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
		String seq = request.getParameter("seq");
		int cpage = 1;
		if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
			cpage = Integer.parseInt(request.getParameter("cpage"));
		}
		
		BoardListTO listTO = new BoardListTO();		// 20180725
		listTO.setCpage(cpage);						// 20180725
		
		BoardTO to = new BoardTO();
		to.setSeq(seq);
		
		BoardDAO dao = new BoardDAO();
		to = dao.boardView(to);
		
		request.setAttribute("to", to);
		request.setAttribute("listTO", listTO);
	}

}

Model2Ex02.model2.DeleteAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardListTO;
import paging1.BoardTO;

public class DeleteAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub		
		int cpage = 1;
		if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
			cpage = Integer.parseInt(request.getParameter("cpage"));
		}
		
		BoardTO to = new BoardTO();
		to.setSeq(request.getParameter("seq"));
		
		BoardDAO dao = new BoardDAO();
		//to = dao.boardView(to);
		to = dao.boardDelete(to);
		//to = dao.boardDeleteOk(to);
		
		BoardListTO listTO = new BoardListTO();		// 20180725
		listTO.setCpage(cpage);						// 20180725
		
		request.setAttribute("to", to);
		request.setAttribute("listTO", listTO);
	}

}

Model2Ex02.model2.DeleteOkAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardTO;

public class DeleteOkAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
		String seq = request.getParameter("seq");
		String password = request.getParameter("password");
		
		BoardTO to = new BoardTO();
		to.setSeq(seq);
		to.setPassword(password);
		
		BoardDAO dao = new BoardDAO();
		int flag = dao.boardDeleteOk(to);
		
		request.setAttribute("flag", flag);
		request.setAttribute("to", to);
	}

}

Model2Ex02.model2.ModifyAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardListTO;
import paging1.BoardTO;

public class ModifyAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		int cpage = 1;
		if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
			cpage = Integer.parseInt(request.getParameter("cpage"));
		}
		
		BoardTO to = new BoardTO();
		to.setSeq(request.getParameter("seq"));
		
		BoardDAO dao = new BoardDAO();
		to = dao.boardModify(to);
		
		BoardListTO listTO = new BoardListTO();		// 20180725
		listTO.setCpage(cpage);						// 20180725
		
		request.setAttribute("to", to);
		request.setAttribute("listTO", listTO);
	}

}

Model2Ex02.model2.ModifyOkAction

package model2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import paging1.BoardDAO;
import paging1.BoardListTO;
import paging1.BoardTO;

public class ModifyOkAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		int cpage = 1;
		if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
			cpage = Integer.parseInt(request.getParameter("cpage"));
		}

		String seq = request.getParameter("seq");
		String subject = request.getParameter("subject");
		String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
		String password = request.getParameter("password");
		String content = request.getParameter("content");
		String wip = request.getRemoteAddr();
		
		BoardTO to = new BoardTO();
		to.setSubject(subject);
		to.setMail(mail);
		to.setPassword(password);
		to.setContent(content);
		to.setSeq(seq);
		
		BoardDAO dao = new BoardDAO();
		
		BoardListTO listTO = new BoardListTO();		// 20180725
		listTO.setCpage(cpage);						// 20180725
		
		int flag = dao.boardModifyOk(to);
		
		request.setAttribute("to", to);
		request.setAttribute("flag", flag);
		request.setAttribute("listTO", listTO);
	}

}

Model2Ex02.WebContent.board_list1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!-- Java 전처리 -->
<%@ page import="paging1.BoardTO" %>		<!-- 20180725 -->
<%@ page import="paging1.BoardListTO" %>	<!-- 20180725 -->	
<%@ page import="java.util.ArrayList" %>	<!-- 20180725 -->
<%
	BoardListTO listTO = (BoardListTO)request.getAttribute("listTO");
	int cpage = listTO.getCpage();

	int totalRecord = listTO.getTotalRecord();	// 20180725
	int totalPage = listTO.getTotalPage();		// 20180725
	int blockPerPage = listTO.getBlockPerPage();		// 한 페이지당 5개	// 20180725
	
	int startBlock = listTO.getStartBlock();	// 20180725
	int endBlock = listTO.getEndBlock();		// 20180725
	
	ArrayList<BoardTO> boardlLists = listTO.getBoardLists();		// 20180725
	
	StringBuffer sb = new StringBuffer();
	
	for(BoardTO to : boardlLists) {
		String seq = to.getSeq();
		String subject = to.getSubject();
		String writer = to.getWriter();
		String wdate = to.getWdate();
		String hit = to.getHit();
		int wgap = to.getWgap();
		
		sb.append("<tr>");
		sb.append("	<td>&nbsp;</td>");
		//sb.append("	<td>").append(rs.getString("seq")).append("</td>");
		sb.append("	<td>" + seq + "</td>");
		if(wgap == 0 ) {
			sb.append("	<td class='left'><a href='./controller?action=view&cpage=" + cpage + "&seq=" + seq + "'>" + subject + "</a>&nbsp;<img src='./images/icon_hot.gif' alt='HOT'></td>");	
		} else {
			sb.append("	<td class='left'><a href='./controller?action=view&cpage=" + cpage + "&seq=" + seq + "'>" + subject + "</a></td>");
		}
		
		sb.append("	<td>" + writer + "</td>");
		sb.append("	<td>" + wdate + "</td>");
		sb.append("	<td>" + hit + "</td>");
		sb.append("	<td>&nbsp;</td>");
		sb.append("</tr>");
	}
%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_list.css">
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<div class="contents_sub">
		<div class="board_top">
			<div class="bold">총 <span class="txt_orange"><%=totalRecord %></span>건</div>
		</div>

		<!--게시판-->
		<div class="board">
			<table>
			<tr>
				<th width="3%">&nbsp;</th>
				<th width="5%">번호</th>
				<th>제목</th>
				<th width="10%">글쓴이</th>
				<th width="17%">등록일</th>
				<th width="5%">조회</th>
				<th width="3%">&nbsp;</th>
			</tr>
			<tr>
			<!-- 시작 -->
			<%= sb %>
			<!-- 끝 -->
			</tr>
			</table>
		</div>	
		<!--//게시판-->

		<div class="align_right">
			<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='controller?action=write&cpage=<%=cpage %>'">쓰기</button>
		</div>
		<!--페이지넘버-->
		<div class="paginate_regular">
			<div class="board_pagetab" align="absmiddle">
<%
	//int startBlock = ((cpage -1) / blockPerPage)*blockPerPage + 1;
	//int endBlock = ((cpage -1) / blockPerPage)*blockPerPage + blockPerPage;
	
	if(endBlock >= totalPage) {
		endBlock = totalPage;
	}
%>
<%
	if(startBlock == 1) {
		out.println("<span class='on'>&lt;&lt;</span>");
	} else {
		out.println("<span class='off'><a href='./controller?action=list&cpage=" + (startBlock - blockPerPage) +"'>&lt;&lt;&nbsp;</a></span>");
		out.println("&nbsp;");
	}
%>
<%
	if(cpage == 1) {
		out.println("<span class='on'>&lt;</span>");
	} else {
		out.println("<span class='off'><a href='./controller?action=list&cpage=" + (cpage-1) + "'>&lt;&nbsp;</a></span>");
		out.println("&nbsp;&nbsp;");
	}
%>
<%
	for(int i=startBlock; i<=endBlock; i++) {
		if(cpage == i) {
			out.println("<span class='on'>[ " + i + " ]</span>");		
		} else {
			out.println("<span class='off'><a href='./controller?action=list&cpage=" + i + "'>" + i + "</a></span>");
			
		}
	}
%>
<%
	if(cpage == totalPage) {
		out.println("<span class='on'>&gt;</span>");
	} else {
		out.println("<span class='off'><a href='./controller?action=list&cpage=" + (cpage+1) + "'>&gt;&nbsp;</a></span>");
		out.println("&nbsp;&nbsp;");
	}
%>
<%
	if(endBlock == totalPage) {
		out.println("<span class='on'>&gt;&gt;</span>");
	} else {
		out.println("<span class='off'><a href='./controller?action=list&cpage=" + (startBlock + blockPerPage) +"'>&gt;&gt;&nbsp;</a></span>");
		out.println("&nbsp;");
	}
%>
			</div>
		</div>
		<!--//페이지넘버-->
	</div>
</div>
<!--//하단 디자인 -->

</body>
</html>

Model2Ex02.WebContent.board_write1

<%@page import="paging1.BoardListTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	BoardListTO listTO = (BoardListTO)request.getAttribute("listTO");
	int cpage = listTO.getCpage();
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			//alert('click');
			if(document.frm.info.checked == false) {
				alert('동의하셔야 합니다.');
				return;
			}
			
			if(document.frm.writer.value.trim() == "") {
				alert('이름을 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.subject.value.trim() == "") {
				alert('제목을 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="write_ok" />
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="" class="board_view_input" /></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				<tr>
					<th>내용</th>
					<td colspan="3"><textarea name="content" class="board_editor_area"></textarea></td>
				</tr>
				<tr>
					<th>이메일</th>
					<td colspan="3"><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></td>
				</tr>
				</table>
				
				<table>
				<tr>
					<br />
					<td style="text-align:left;border:1px solid #e0e0e0;background-color:f9f9f9;padding:5px">
						<div style="padding-top:7px;padding-bottom:5px;font-weight:bold;padding-left:7px;font-family: Gulim,Tahoma,verdana;">※ 개인정보 수집 및 이용에 관한 안내</div>
						<div style="padding-left:10px;">
							<div style="width:97%;height:95px;font-size:11px;letter-spacing: -0.1em;border:1px solid #c5c5c5;background-color:#fff;padding-left:14px;padding-top:7px;">
								1. 수집 개인정보 항목 : 회사명, 담당자명, 메일 주소, 전화번호, 홈페이지 주소, 팩스번호, 주소 <br />
								2. 개인정보의 수집 및 이용목적 : 제휴신청에 따른 본인확인 및 원활한 의사소통 경로 확보 <br />
								3. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다. <br />
								4. 그 밖의 사항은 개인정보취급방침을 준수합니다.
							</div>
						</div>
						<div style="padding-top:7px;padding-left:5px;padding-bottom:7px;font-family: Gulim,Tahoma,verdana;">
							<input type="checkbox" name="info" value="1" class="input_radio"> 개인정보 수집 및 이용에 대해 동의합니다.
						</div>
					</td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./controller?action=list&cpage=<%=cpage %>'">목록</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">등록</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex02.WebContent.board_write1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
	int flag = (Integer)request.getAttribute("flag");
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글쓰기에 성공했습니다.');");
		out.println("location.href='./controller?action=list';");
	} else if(flag == 1) {
		out.println("alert('글쓰기에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

Model2Ex02.WebContent.board_view1

<%@page import="paging1.BoardListTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="paging1.BoardTO" %>

<%

	BoardTO to = (BoardTO)request.getAttribute("to");
	BoardListTO listTO = (BoardListTO)request.getAttribute("listTO");
	int cpage = listTO.getCpage();
	
	String seq = to.getSeq();
	String subject = to.getSubject();
	String writer = to.getWriter();
	String wdate = to.getWdate();
	String hit = to.getHit();
	String content = to.getContent();
	String mail = to.getMail();
%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_view.css">
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<div class="contents_sub">
		<!--게시판-->
		<div class="board_view">
			<table>
			<tr>
				<th width="10%">제목</th>
				<td width="60%"><%= subject %></td>
				<th width="10%">등록일</th>
				<td width="20%"><%= wdate %></td>
			</tr>
			<tr>
				<th>글쓴이</th>
				<td><%= writer %><%= '(' + mail + ')' %></td>
				<th>조회</th>
				<td><%= hit %></td>
			</tr>
			<tr>
				<td colspan="4" height="200" valign="top" style="padding: 20px; line-height: 160%"><%= content %></td>
			</tr>
			</table>
		</div>

		<div class="btn_area">
			<div class="align_left">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=list&cpage=<%=cpage %>'">목록</button>
			</div>
			<div class="align_right">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=modify&cpage=<%=cpage %>&seq=<%= seq %>'">수정</button>
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=delete&cpage=<%=cpage %>&seq=<%= seq %>'">삭제</button>
				<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='controller?action=write&cpage=<%=cpage %>'">쓰기</button>
			</div>
		</div>	
		<!--//게시판-->
	</div>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex02.WebContent.board_delete1

<%@page import="paging1.BoardListTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="paging1.BoardTO" %>		<!-- 20180725 -->

<%
	BoardTO to = (BoardTO)request.getAttribute("to");

	BoardListTO listTO = (BoardListTO)request.getAttribute("listTO");
	int cpage = listTO.getCpage();

	String seq = to.getSeq();
	
	String subject = to.getSubject();
	String writer = to.getWriter();
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="delete_ok" />
	<input type="hidden" name="seq" value="<%=seq %>" />	<!-- delete할 때 seq를 받아오기 위해 hidden으로해서 작성 / 브라우저에서 소스보기 하면 값 확인가능 -->
	<input type="hidden" name="cpage" value="<%=cpage %>" />
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="<%= writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="<%= subject %>" class="board_view_input" readonly/></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=list&cpage=<%=cpage %>'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=view&cpage=<%=cpage %>&seq=<%=seq %>'">보기</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">삭제</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex02.WebContent.board_delete1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="paging1.BoardTO" %>		<!-- 20180725 -->	

<%
	BoardTO to = (BoardTO)request.getAttribute("to");
	String seq = to.getSeq();
	int flag = (Integer)request.getAttribute("flag");
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 삭제에 성공했습니다.');");
		out.println("location.href='./controller?action=list&seq=" + seq +"'");
	} else if(flag == 1) {
		out.println("alert('비밀번호 오류입니다.');");
		out.println("history.back();");
	} else if(flag == 2) {
		out.println("alert('글 삭제에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

Model2Ex02.WebContent.board_modify1

<%@page import="paging1.BoardListTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="paging1.BoardTO" %>

<%
	BoardTO to = (BoardTO)request.getAttribute("to");
	
	BoardListTO listTO = (BoardListTO)request.getAttribute("listTO");
	int cpage = listTO.getCpage();
	String seq = to.getSeq();
	String subject = to.getSubject();
	String writer = to.getWriter();
	String content = to.getContent();
	String mail[] = to.getMail().split("@");
	if(mail.length == 0) {
		mail = new String[] {"", ""};
	}
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="./css/board_write.css">
<script type="text/javascript">
	window.onload = function() {
		document.getElementById('submit1').onclick = function() {
			if(document.frm.writer.value.trim() == "") {
				alert('이름을 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.password.value.trim() == "") {
				alert('비밀번호를 입력하셔야 합니다.');
				return;
			}
			
			if(document.frm.subject.value.trim() == "") {
				alert('제목을 입력하셔야 합니다.');
				return;
			}
			
			document.frm.submit();
		};
	};
</script>
</head>

<body>
<!-- 상단 디자인 -->
<div class="con_title">
	<h3>게시판</h3>
	<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
	<form action="./controller" method="post" name="frm">
	<input type="hidden" name="action" value="modify_ok" />
	<input type="hidden" name="seq" value="<%=seq %>" />
	<input type="hidden" name="cpage" value="<%=cpage %>" />
		<div class="contents_sub">	
			<!--게시판-->
			<div class="board_write">
				<table>
				<tr>
					<th class="top">글쓴이</th>
					<td class="top" colspan="3"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
				</tr>
				<tr>
					<th>제목</th>
					<td colspan="3"><input type="text" name="subject" value="<%=subject %>" class="board_view_input" /></td>
				</tr>
				<tr>
					<th>비밀번호</th>
					<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
				</tr>
				<tr>
					<th>내용</th>
					<td colspan="3"><textarea name="content" class="board_editor_area"><%=content %></textarea></td>
				</tr>
				<tr>
					<th>이메일</th>
					<td colspan="3"><input type="text" name="mail1" value="<%=mail[0] %>" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="<%=mail[1] %>" class="board_view_input_mail"/></td>
				</tr>
				</table>
			</div>
			
			<div class="btn_area">
				<div class="align_left">
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=list&cpage=<%=cpage %>'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='controller?action=view&cpage=<%=cpage %>&seq=<%=seq %>'">보기</button>
				</div>
				<div class="align_right">
					<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">수정</button>
				</div>
			</div>
			<!--//게시판-->
		</div>
	</form>
</div>
<!-- 하단 디자인 -->

</body>
</html>

Model2Ex02.WebContent.board_modify1_ok

<%@page import="paging1.BoardListTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>

<%@ page import="paging1.BoardTO" %>

<%
	BoardTO to = (BoardTO)request.getAttribute("to");
	String seq = to.getSeq();
	
	BoardListTO listTO = (BoardListTO)request.getAttribute("listTO");
	int cpage = listTO.getCpage();
	
	int flag = (Integer)request.getAttribute("flag");
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글수정에 성공했습니다.');");
		out.println("location.href='controller?action=list&cpage=" + cpage + "&seq=" + seq + "'");
	} else if(flag == 1) {
		out.println("alert('비밀번호 틀립니다.');");
		out.println("history.back();");
	} else {
		out.println("alert('글수정에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

board_list1

board_write1

board_write1_ok

board_view

board_modify1

board_modify1_ok

board_delete1

board_delete1_ok

반응형

댓글