본문 바로가기
Web & Mobile/JSP

Lecture 49 - JSP(7) 페이지 수를 나타내는 Model1 기반 게시판

by Bennyziio 2019. 5. 24.
반응형

페이지 수를 나타내고 누르면 이동하는 구문 추가하기
우선 데이터를 200개 추가하기
BoardEx01.paging1.board_write2_ok

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

<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>
    
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	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();

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 1;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();	
		
		// 100개의 데이터를 만듬
		for(int i=1; i<=100; i++) {
			String sql = "insert into board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate)";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, "제목" + i);
			pstmt.setString(2, "이름" + i);
			pstmt.setString(3, "test@test.com");
			pstmt.setString(4, "1234");
			pstmt.setString(5, "내용" + i);
			pstmt.setString(6, "000.000.000.000");
			
			pstmt.executeUpdate();
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	out.println("alert('글쓰기에 성공했습니다.');");
	out.println("location.href='./board_list1.jsp';");
	out.println("</script>");
%>

BoardEx01.paging1.board_list1

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

<!-- Java 전처리 -->
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	int cpage = 1;
	if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
		cpage = Integer.parseInt(request.getParameter("cpage"));
	}
	
	int recordPerpage = 10;
	int totalRecord = 0;
	int totalPage = 1;
	int blockPerPage = 5;		// 한 페이지당 5개

	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		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_SENSITIVE, ResultSet.CONCUR_READ_ONLY);			

		rs = pstmt.executeQuery();
		// 커서를 맨 마지막행으로 이동
		rs.last();
		// 데이터 개수가 나옴
		totalRecord = rs.getRow();
		rs.beforeFirst();
		
		// 전체 페이지 수 구하는 공식
		totalPage = ((totalRecord -1) / recordPerpage) + 1;
		
		int skip = (cpage -1) * recordPerpage;
		// absolute - 읽을 위치(커서 위치) 지정
		if(skip != 0) {
			rs.absolute(skip);
		}
		// i<recordPerpage && rs.next() - recordPerpage 이하이면서 동시에 다음 페이지를 읽을 준비
		for(int i=0; i<recordPerpage && rs.next(); i++) {
			sb.append("<tr>");
			sb.append("	<td>&nbsp;</td>");
			//sb.append("	<td>").append(rs.getString("seq")).append("</td>");
			sb.append("	<td>" + rs.getString("seq") + "</td>");
			if(rs.getInt("wgap") == 0 ) {
				sb.append("	<td class='left'><a href='./board_view1.jsp?cpage=" + cpage + "&seq=" + rs.getString("seq") + "'>" + rs.getString("subject") + "</a>&nbsp;<img src='../images/icon_hot.gif' alt='HOT'></td>");	
			} else {
				sb.append("	<td class='left'><a href='./board_view1.jsp?cpage=" + cpage + "&seq=" + rs.getString("seq") + "'>" + rs.getString("subject") + "</a></td>");
			}
			
			sb.append("	<td>" + rs.getString("writer") + "</td>");
			sb.append("	<td>" + rs.getString("wdate") + "</td>");
			sb.append("	<td>" + rs.getString("hit") + "</td>");
			sb.append("	<td>&nbsp;</td>");
			sb.append("</tr>");
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>

<!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"			<%= sb %>
			<!-- 끝 -->
			</tr>
			</table>
		</div>	
		<!--//게시판-->

		<div class="align_right">
			<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?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='./board_list1.jsp?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='./board_list1.jsp?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='./board_list1.jsp?cpage=" + i + "'>" + i + "</a></span>");
			
		}
	}
%>
<%
	if(cpage == totalPage) {
		out.println("<span class='on'>&gt;</span>");
	} else {
		out.println("<span class='off'><a href='./board_list1.jsp?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='./board_list1.jsp?cpage=" + (startBlock + blockPerPage) +"'>&gt;&gt;&nbsp;</a></span>");
		out.println("&nbsp;");
	}
%>
			</div>
		</div>
		<!--//페이지넘버-->
	</div>
</div>
<!--//하단 디자인 -->

</body>
</html>

BoardEx01.paging1.board_write1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");

	String cpage = request.getParameter("cpage");
%>
<!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="./board_write1_ok.jsp" method="post" name="frm">
		<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='board_list1.jspcpage=<%=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>

BoardEx01.paging1.board_write1_ok

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

<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>
    
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	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();

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 1;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();		
		
		String sql = "insert into board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate)";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, subject);
		pstmt.setString(2, writer);
		pstmt.setString(3, mail);
		pstmt.setString(4, password);
		pstmt.setString(5, content);
		pstmt.setString(6, wip);
	
		int result = pstmt.executeUpdate();
		if(result == 1) {
			flag = 0;
		}
		
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글쓰기에 성공했습니다.');");
		out.println("location.href='./board_list1.jsp';");
	} else if(flag == 1) {
		out.println("alert('글쓰기에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

BoardEx01.paging1.board_view1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");
	
	String cpage = request.getParameter("cpage");
	String seq = request.getParameter("seq");
	
	String subject = "";
	String writer = "";
	String wdate = "";
	String hit = "";
	String content = "";
	String mail = "";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		
		// 조회수
		String sql = "update board1 set hit = hit + 1 where seq=?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
		
		pstmt.executeUpdate();
		
		// 조회
		sql = "select subject, writer, wdate, hit, content, mail from board1 where seq = ?";
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
				
		rs = pstmt.executeQuery();
		if(rs.next()) {
			subject = rs.getString("subject");
			writer = rs.getString("writer");
			wdate = rs.getString("wdate");
			hit = rs.getString("hit");
			content = rs.getString("content") == null ? "" : rs.getString("content").replaceAll("\n", "<br />");
			mail = rs.getString("mail");
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>

<!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='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
			</div>
			<div class="align_right">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_modify1.jsp?cpage=<%=cpage %>&seq=<%= seq %>'">수정</button>
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_delete1.jsp?cpage=<%=cpage %>&seq=<%= seq %>'">삭제</button>
				<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jspcpage=<%=cpage %>'">쓰기</button>
			</div>
		</div>	
		<!--//게시판-->
	</div>
</div>
<!-- 하단 디자인 -->

</body>
</html>

BoardEx01.paging1.board_modify1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String seq = request.getParameter("seq");
	String cpage = request.getParameter("cpage");
	
	String subject = "";
	String writer = "";
	String content = "";
	String mail[] = null;
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		String sql = "select writer, subject, content, mail from board1 where seq = ?";
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
				
		rs = pstmt.executeQuery();
		if(rs.next()) {
			writer = rs.getString("writer");
			subject = rs.getString("subject");
			content = rs.getString("content") == null ? "" : rs.getString("content").replaceAll("\n", "<br />");
			mail = rs.getString("mail").split("@");
			if(mail.length == 0) {
				mail = new String[] {"", ""};
			}
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>
<!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="./board_modify1_ok.jsp" method="post" name="frm">
	<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='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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>

BoardEx01.paging1.board_modify1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	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();
	String cpage = request.getParameter("cpage");

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 2;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		
		String sql = "update board1 set subject=?, mail=?, password=?, content=? where seq = ? and password = ?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, subject);
		pstmt.setString(2, mail);
		pstmt.setString(3, password);
		pstmt.setString(4, content);
		pstmt.setString(5, seq);
		pstmt.setString(6, password);
	
		int result = pstmt.executeUpdate();
		if(result == 1) {
			// 정상
			flag = 0;
		} else if (result == 0) {
			// 비밀번호 오류
			flag = 1;
		}
		
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 수정에 성공했습니다.');");
		out.println("location.href='./board_list1.jsp?cpage=" + cpage + "&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>");
%>

BoardEx01.paging1.board_delete1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String seq = request.getParameter("seq");
	String cpage = request.getParameter("cpage");
	
	String subject = "";
	String writer = "";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		String sql = "select subject, writer from board1 where seq = ?";
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
				
		rs = pstmt.executeQuery();
		if(rs.next()) {
			subject = rs.getString("subject");
			writer = rs.getString("writer");
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>
<!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="./board_delete1_ok.jsp" method="post" name="frm">
	<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='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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>

BoardEx01.paging1.board_delete1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String seq = request.getParameter("seq");
	String password = request.getParameter("password");

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 2;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		
		String sql = "delete from board1 where seq = ? and password = ?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
		pstmt.setString(2, password);
	
		int result = pstmt.executeUpdate();
		if(result == 1) {
			// 정상
			flag = 0;
		} else if (result == 0) {
			// 비밀번호 오류
			flag = 1;
		}
		
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 삭제에 성공했습니다.');");
		out.println("location.href='./board_list1.jsp?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>");
%>

emot_board1도 똑같이 만들어 보자

BoardEx01.emot_board2.board_write2_ok

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

<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>
    
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	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 emot = request.getParameter("emot");

	String wip = request.getRemoteAddr();

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 1;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();		
		
		for(int i=1; i<=100; i++) {
			String sql = "insert into emot_board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate, ?)";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, "제목" + i);
			pstmt.setString(2, "이름" + i);
			pstmt.setString(3, "test@test.com");
			pstmt.setString(4, "1234");
			pstmt.setString(5, "내용" + i);
			pstmt.setString(6, "000.000.000.000");
			pstmt.setString(7, "emot03");
			int result = pstmt.executeUpdate();
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	out.println("alert('글쓰기에 성공했습니다.');");
	out.println("location.href='./board_list1.jsp';");
	out.println("</script>");
%>

BoardEx01.emot_board2.board_list1

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

<!-- Java 전처리 -->
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");
	
	int cpage = 1;
	if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
		cpage = Integer.parseInt(request.getParameter("cpage"));
	}
	
	int recordPerpage = 10;
	int totalRecord = 0;
	int totalPage = 1;
	int blockPerPage = 5;		// 한 페이지당 5개
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, hit, trunc(sysdate-wdate) wgap from emot_board1 order by seq desc";
		pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);		

		rs = pstmt.executeQuery();
		// 커서를 맨 마지막행으로 이동
		rs.last();
		// 데이터 개수가 나옴
		totalRecord = rs.getRow();
		rs.beforeFirst();
		
		// 전체 페이지 수 구하는 공식
		totalPage = ((totalRecord -1) / recordPerpage) + 1;
		
		int skip = (cpage -1) * recordPerpage;
		// absolute - 읽을 위치(커서 위치) 지정
		if(skip != 0) {
			rs.absolute(skip);
		}
		
		// i<recordPerpage && rs.next() - recordPerpage 이하이면서 동시에 다음 페이지를 읽을 준비
		for(int i=0; i<recordPerpage && rs.next(); i++) {
			sb.append("<tr>");
			sb.append("	<td>&nbsp;</td>");
			//sb.append("	<td>").append(rs.getString("seq")).append("</td>");
			sb.append("	<td>" + rs.getString("seq") + "</td>");
			if(rs.getInt("wgap") == 0 ) {
				sb.append("	<td class='left'><a href='./board_view1.jsp?cpage=" + cpage + "&seq=" + rs.getString("seq") + "'>" + rs.getString("subject") + "</a>&nbsp;<img src='../images/icon_hot.gif' alt='HOT'></td>");	
			} else {
				sb.append("	<td class='left'><a href='./board_view1.jsp?cpage=" + cpage + "&seq=" + rs.getString("seq") + "'>" + rs.getString("subject") + "</a></td>");
			}
			
			sb.append("	<td>" + rs.getString("writer") + "</td>");
			sb.append("	<td>" + rs.getString("wdate") + "</td>");
			sb.append("	<td>" + rs.getString("hit") + "</td>");
			sb.append("	<td>&nbsp;</td>");
			sb.append("</tr>");
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,mini="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='board_write1.jsp?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='./board_list1.jsp?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='./board_list1.jsp?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='./board_list1.jsp?cpage=" + i + "'>" + i + "</a></span>");
			
		}
	}
%>
<%
	if(cpage == totalPage) {
		out.println("<span class='on'>&gt;</span>");
	} else {
		out.println("<span class='off'><a href='./board_list1.jsp?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='./board_list1.jsp?cpage=" + (startBlock + blockPerPage) +"'>&gt;&gt;&nbsp;</a></span>");
		out.println("&nbsp;");
	}
%>
			</div>
		</div>
		<!--//페이지넘버-->
	</div>
</div>
<!--//하단 디자인 -->

</body>
</html>

BoardEx01.emot_board2.board_write1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
adio" name="emot" value="emot26" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot27.png" width="25" /><br />
								<input type="radio" name="emot" value="emot27" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot28.png" width="25" /><br />
								<input type="radio" name="emot" value="emot28" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot29.png" width="25" /><br />
								<input type="radio" name="emot" value="emot29" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot30.png" width="25" /><br />
								<input type="radio" name="emot" value="emot30" class="input_radio" />
							</td>
						</tr>
						<tr>
							<td>
								<img src="../images/emoticon/emot31.png" width="25"/><br />
								<input type="radio" name="emot" value="emot31" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot32.png" width="25" /><br />
								<input type="radio" name="emot" value="emot32" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot33.png" width="25" /><br />
								<input type="radio" name="emot" value="emot33" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot34.png" width="25" /><br />
								<input type="radio" name="emot" value="emot34" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot35.png" width="25" /><br />
								<input type="radio" name="emot" value="emot35" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot36.png" width="25" /><br />
								<input type="radio" name="emot" value="emot36" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot37.png" width="25" /><br />
								<input type="radio" name="emot" value="emot37" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot38.png" width="25" /><br />
								<input type="radio" name="emot" value="emot38" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot39.png" width="25" /><br />
								<input type="radio" name="emot" value="emot39" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot40.png" width="25"/><br />
								<input type="radio" name="emot" value="emot40" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot41.png" width="25" /><br />
								<input type="radio" name="emot" value="emot41" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot42.png" width="25" /><br />
								<input type="radio" name="emot" value="emot42" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot43.png" width="25" /><br />
								<input type="radio" name="emot" value="emot43" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot44.png" width="25" /><br />
								<input type="radio" name="emot" value="emot44" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot45.png" width="25" /><br />
								<input type="radio" name="emot" value="emot45" class="input_radio" />
							</td>
						</tr>
						</table>
					</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='board_list1.jsp?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>

BoardEx01.emot_board2.board_write1_ok

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

<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>
    
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String subject = request.getParameter("subject");
	String writer = request.getParameter("writer");
	String mail = "@";
	if(!request.getParameter("mail1").equals("") && !request.getParameter("mail2").equals("")) {
		mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
	}
	String password = request.getParameter("password");
	String content = request.getParameter("content");
	String emot = request.getParameter("emot").replaceAll("emot", "");

	String wip = request.getRemoteAddr();

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 1;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();		
		
		String sql = "insert into emot_board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate, ?)";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, subject);
		pstmt.setString(2, writer);
		pstmt.setString(3, mail);
		pstmt.setString(4, password);
		pstmt.setString(5, content);
		pstmt.setString(6, wip);
		pstmt.setString(7, emot);
		
	
		int result = pstmt.executeUpdate();
		if(result == 1) {
			flag = 0;
		}
		
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글쓰기에 성공했습니다.');");
		out.println("location.href='./board_list1.jsp';");
	} else if(flag == 1) {
		out.println("alert('글쓰기에 실패했습니다.');");
		out.println("history.back();");
	}
	out.println("</script>");
%>

BoardEx01.emot_board2.board_view1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String cpage = request.getParameter("cpage");
	String seq = request.getParameter("seq");
	
	String subject = "";
	String writer = "";
	String wdate = "";
	String hit = "";
	String content = "";
	String mail = "";
	String emot = "";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		
		// 조회수
		String sql = "update emot_board1 set hit = hit + 1 where seq=?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
		
		pstmt.executeUpdate();
		
		// 조회
		sql = "select subject, writer, wdate, hit, content, mail, emot from emot_board1 where seq = ?";
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
				
		rs = pstmt.executeQuery();
		if(rs.next()) {
			subject = rs.getString("subject");
			writer = rs.getString("writer");
			wdate = rs.getString("wdate");
			hit = rs.getString("hit");
			content = rs.getString("content") == null ? "" : rs.getString("content").replaceAll("\n", "<br />");
			mail = rs.getString("mail").equals("@") ? "" : "(" + rs.getString("mail") + ")";
			emot = rs.getString("emot").replaceAll("emot", "");
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>

<!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%">(<img src="../images/emoticon/emot<%=emot %>.png" width="15"/>)&nbsp;<%= 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='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
			</div>
			<div class="align_right">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_modify1.jsp?cpage=<%=cpage %>&seq=<%= seq %>'">수정</button>
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_delete1.jsp?cpage=<%=cpage %>&seq=<%= seq %>'">삭제</button>
				<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?cpage=<%=cpage %>'">쓰기</button>
			</div>
		</div>	
		<!--//게시판-->
	</div>
</div>
<!-- 하단 디자인 -->

</body>
</html>

BoardEx01.emot_board2.board_modify1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String seq = request.getParameter("seq");
	String cpage = request.getParameter("cpage");
	
	String subject = "";
	String writer = "";
	String content = "";
	String mail[] = null;
	String emot = "";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		String sql = "select writer, subject, content, mail, emot from emot_board1 where seq = ?";
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
				
		rs = pstmt.executeQuery();
		if(rs.next()) {
			writer = rs.getString("writer");
			subject = rs.getString("subject");
			content = rs.getString("content") == null ? "" : rs.getString("content").replaceAll("\n", "<br />");
			mail = rs.getString("mail").split("@");			
			if(mail.length == 0) {
				mail = new String[] {"", ""};
			}
			emo_radio" <%=emot.equals("33") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot34.png" width="25" /><br />
								<input type="radio" name="emot" value="emot34" class="input_radio" <%=emot.equals("34") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot35.png" width="25" /><br />
								<input type="radio" name="emot" value="emot35" class="input_radio" <%=emot.equals("35") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot36.png" width="25" /><br />
								<input type="radio" name="emot" value="emot36" class="input_radio" <%=emot.equals("36") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot37.png" width="25" /><br />
								<input type="radio" name="emot" value="emot37" class="input_radio" <%=emot.equals("37") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot38.png" width="25" /><br />
								<input type="radio" name="emot" value="emot38" class="input_radio" <%=emot.equals("38") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot39.png" width="25" /><br />
								<input type="radio" name="emot" value="emot39" class="input_radio" <%=emot.equals("39") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot40.png" width="25"/><br />
								<input type="radio" name="emot" value="emot40" class="input_radio" <%=emot.equals("40") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot41.png" width="25" /><br />
								<input type="radio" name="emot" value="emot41" class="input_radio" <%=emot.equals("41") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot42.png" width="25" /><br />
								<input type="radio" name="emot" value="emot42" class="input_radio" <%=emot.equals("42") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot43.png" width="25" /><br />
								<input type="radio" name="emot" value="emot43" class="input_radio" <%=emot.equals("43") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot44.png" width="25" /><br />
								<input type="radio" name="emot" value="emot44" class="input_radio" <%=emot.equals("44") ? "checked = 'checked'" : "" %> />
							</td>
							<td>
								<img src="../images/emoticon/emot45.png" width="25" /><br />
								<input type="radio" name="emot" value="emot45" class="input_radio" <%=emot.equals("45") ? "checked = 'checked'" : "" %> />
							</td>
						</tr>
						</table>
					</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='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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>

BoardEx01.emot_board2.board_modify1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>a
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	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();
	String emot = request.getParameter("emot");
	String cpage = request.getParameter("cpage");

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 2;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		
		String sql = "update emot_board1 set subject=?, mail=?, password=?, content=?, emot=? where seq = ? and password = ?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, subject);
		pstmt.setString(2, mail);
		pstmt.setString(3, password);
		pstmt.setString(4, content);
		pstmt.setString(5, emot);
		pstmt.setString(6, seq);
		pstmt.setString(7, password);
	
		int result = pstmt.executeUpdate();
		if(result == 1) {
			// 정상
			flag = 0;
		} else if (result == 0) {
			// 비밀번호 오류
			flag = 1;
		}
		
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 수정에 성공했습니다.');");
		out.println("location.href='./board_list1.jsp?cpage=" + cpage + "&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>");
%>

BoardEx01.emot_board2.board_delete1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String seq = request.getParameter("seq");
	String cpage = request.getParameter("cpage");
	
	String subject = "";
	String writer = "";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		String sql = "select subject, writer from emot_board1 where seq = ?";
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
				
		rs = pstmt.executeQuery();
		if(rs.next()) {
			subject = rs.getString("subject");
			writer = rs.getString("writer");
		}
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(rs != null) rs.close();
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
%>
<!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="./board_delete1_ok.jsp" method="post" name="frm">
	<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='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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>

BoardEx01.emot_board2.board_delete1_ok

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>

<%
	request.setCharacterEncoding("utf-8");

	String seq = request.getParameter("seq");
	String password = request.getParameter("password");

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	int flag = 2;
	
	try {
		Context initCtx = new InitialContext();
		Context envCtx = (Context)initCtx.lookup("java:comp/env");
		DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
		conn = datasource.getConnection();
		
		String sql = "delete from emot_board1 where seq = ? and password = ?";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, seq);
		pstmt.setString(2, password);
	
		int result = pstmt.executeUpdate();
		if(result == 1) {
			// 정상
			flag = 0;
		} else if (result == 0) {
			// 비밀번호 오류
			flag = 1;
		}
		
	} catch(NamingException e) {
		System.out.println("[에러] " + e.getMessage());
	} catch(SQLException e) {
		System.out.println("[에러] " + e.getMessage());
	} finally {
		if(pstmt != null) pstmt.close();
		if(conn != null) conn.close();
	}
	
	out.println("<script type='text/javascript'>");
	if(flag == 0) {
		out.println("alert('글 삭제에 성공했습니다.');");
		out.println("location.href='./board_list1.jsp';");
	} 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>");
%>
반응형

댓글