본문 바로가기
Web & Mobile/JSP

Lecture 47 - JSP(5) 게시판에 이모티콘 추가하기

by Bennyziio 2019. 5. 22.
반응형

Lecture 46에서 한 board_list1에서 HOT 아이콘이 뜨는데 이건 최신글일때(기간을 정해줘야한다) 적용되는거로 수정해보자.

SQL> select wdate from board1;

WDATE
--------
18/07/19
18/07/19
18/07/19
18/07/19
18/07/19
18/07/19
18/07/19

7 행이 선택되었습니다.

SQL> select sysdate - wdate from board1;

SYSDATE-WDATE
-------------
   .814583333
   .770358796
    .65619213
   .852164352
   .816435185
   .795416667
   .777546296

7 행이 선택되었습니다.

SQL> select to_date('18/07/20') - wdate from board1;

TO_DATE('18/07/20')-WDATE
-------------------------
               .405509259
               .361284722
               .247118056
               .443090278
               .407361111
               .386342593
               .368472222

7 행이 선택되었습니다.

SQL> select to_date('18/07/21') - wdate from board1;

TO_DATE('18/07/21')-WDATE
-------------------------
               1.40550926
               1.36128472
               1.24711806
               1.44309028
               1.40736111
               1.38634259
               1.36847222

7 행이 선택되었습니다.
SQL> select trunc(to_date('18/07/21') - wdate) from board1;

TRUNC(TO_DATE('18/07/21')-WDATE)
--------------------------------
                               1
                               1
                               1
                               1
                               1
                               1
                               1

7 행이 선택되었습니다.

SQL> select trunc(sysdate - wdate) from board1;

TRUNC(SYSDATE-WDATE)
--------------------
                   0
                   0
                   0
                   0
                   0
                   0
                   0

7 행이 선택되었습니다.

board1.board_list1 - 하루 뒤 HOT 아이콘 사라지게 IF문으로 나뉘어서 작성

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

<!-- Java 전처리 -->
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>

<%
	String dbUrl = "jdbc:oracle:thin:@localhost:1521:orcl";
	String dbUser = "project";
	String dbPassword = "project";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
		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);		

		rs = pstmt.executeQuery();
		while(rs.next()) {
			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?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?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 (ClassNotFoundException 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_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">1</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='board_write1.jsp'">쓰기</button>
		</div>
	</div>
</div>
<!--//하단 디자인 -->

</body>
</html>

board1.board_view1 - 조회수 적용 및 내용 엔터친 내용이 한줄로 써지는거 수정 및 NULL값일 경우 출력 시키는 구문 추가

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="java.sql.DriverManager" %>
<%@ 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 subject = "";
	String writer = "";
	String wdate = "";
	String hit = "";
	String content = "";
	String mail = "";

	String dbUrl = "jdbc:oracle:thin:@localhost:1521:orcl";
	String dbUser = "project";
	String dbPassword = "project";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
		
		// 조회수
		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 (ClassNotFoundException 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'">목록</button>
			</div>
			<div class="align_right">
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_modify1.jsp?seq=<%= seq %>'">수정</button>
				<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_delete1.jsp?seq=<%= seq %>'">삭제</button>
				<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp'">쓰기</button>
			</div>
		</div>	
		<!--//게시판-->
	</div>
</div>
<!-- 하단 디자인 -->

</body>
</html>

board1.board_modify1

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ page import="java.sql.DriverManager" %>
<%@ 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 subject = "";
	String writer = "";
	String content = "";
	String mail[] = null;
	
	
	String dbUrl = "jdbc:oracle:thin:@localhost:1521:orcl";
	String dbUser = "project";
	String dbPassword = "project";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
		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 (ClassNotFoundException 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 %>" />
		<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'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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>

커넥션 풀
: 커넥션 풀 기법이란 데이터베이스와 연결된 커넥션을 미리 만들어서 풀(pool) 속에 저장해 두고 있다가 필요할 때에 커넥션을 풀에서 가져다 쓰고 다시 풀에 반환하는 기법을 의미한다.

풀 속에 데이터베이스와 연결된 커넥션을 미리 생성해 두고 커넥션이 필요하면 커넥션을 새로 생성하지 않고 미리 생성된 커넥션을 가져다가 사용하고 사용이 끝나면 풀에 반환한다

커넥션 풀의 특징
1. 풀 속에 미리 커넥션이 생성되어 있기 때문에 커넥션을 생성하는 데 드는 연결 시간을 줄 일 수 있다.
2. 커넥션을 계속해서 재사용하기 때문에 생성되는 커넥션 수가 일정하게 유지된다.

context.xml - 톰캣이 데이터베이스에 연결하는 것

<?xml version="1.0" encoding="utf-8" ?>
<Context>
	<Resource
		name="jdbc/oracle1"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="oracle.jdbc.driver.OracleDriver"
		url="jdbc:oracle:thin:@localhost:1521:orcl"
		username="scott"
		password="tiger"
		maxTotal="20"
		maxWaitMillis="5000"/>
</Context>

JSPEx02.jdbc2 - 풀링을 시작하기 위한 전초작업

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

<!-- JNDI 처리 -->
<%@ 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" %>

<%
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	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 deptno, dname, loc from dept";
		pstmt = conn.prepareStatement(sql);
		
		rs = pstmt.executeQuery();
		while(rs.next()) {
			out.println(rs.getString("deptno") + "<br />");
		}
	} 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();
	}
%>

* 톰캣을 중지하고 시작해야 함을 주의!!

board2.board_write1_ok - context로 바꿔보기

<%@ page import="java.sql.DriverManager" %>

위를 아래와 같이 수정

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

그리고

Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);

위를 아래와 같이 수정

Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
DataSource datasource = (DataSource)envCtx.lookup("jdbc/oracle1");
conn = datasource.getConnection();

그리고

catch (ClassNotFoundException e)

위를 아래와 같이 수정

catch(NamingException e)

게시판에 이모티콘 추가하기

boardEx01.emot_board1.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="./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>
				<tr>
					<th>이모티콘</th>
					<td colspan="3" align="center">
						<table>
						<tr>
							<td>
								<img src="../images/emoticon/emot01.png" width="25"/><br />
								<input type="radio" name="emot" value="emot01" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot02.png" width="25" /><br />
								<input type="radio" name="emot" value="emot02" class="input_radio" checked="checked"/>
							</td>
							<td>
								<img src="../images/emoticon/emot03.png" width="25" /><br />
								<input type="radio" name="emot" value="emot03" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot04.png" width="25" /><br />
								<input type="radio" name="emot" value="emot04" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot05.png" width="25" /><br />
								<input type="radio" name="emot" value="emot05" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot06.png" width="25" /><br />
								<input type="radio" name="emot" value="emot06" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot07.png" width="25" /><br />
								<input type="radio" name="emot" value="emot07" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot08.png" width="25" /><br />
								<input type="radio" name="emot" value="emot08" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot09.png" width="25" /><br />
								<input type="radio" name="emot" value="emot09" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot10.png" width="25" /><br />
								<input type="radio" name="emot" value="emot10" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot11.png" width="25"/><br />
								<input type="radio" name="emot" value="emot11" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot12.png" width="25" /><br />
								<input type="radio" name="emot" value="emot12" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot13.png" width="25" /><br />
								<input type="radio" name="emot" value="emot13" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot14.png" width="25" /><br />
								<input type="radio" name="emot" value="emot14" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot15.png" width="25" /><br />
								<input type="radio" name="emot" value="emot15" class="input_radio" />
							</td>
						</tr>
						<tr>
							<td>
								<img src="../images/emoticon/emot16.png" width="25"/><br />
								<input type="radio" name="emot" value="emot16" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot17.png" width="25" /><br />
								<input type="radio" name="emot" value="emot17" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot18.png" width="25" /><br />
								<input type="radio" name="emot" value="emot18" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot19.png" width="25" /><br />
								<input type="radio" name="emot" value="emot19" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot20.png" width="25" /><br />
								<input type="radio" name="emot" value="emot20" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot21.png" width="25" /><br />
								<input type="radio" name="emot" value="emot21" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot22.png" width="25" /><br />
								<input type="radio" name="emot" value="emot22" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot23.png" width="25" /><br />
								<input type="radio" name="emot" value="emot23" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot24.png" width="25" /><br />
								<input type="radio" name="emot" value="emot24" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot25.png" width="25"/><br />
								<input type="radio" name="emot" value="emot25" class="input_radio" />
							</td>
							<td>
								<img src="../images/emoticon/emot26.png" width="25" /><br />
								<input type="radio" 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'">목록</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_board1.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, emot);
		pstmt.setString(7, 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.emot_board1.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" %>

<%
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	StringBuffer sb = new StringBuffer();
	
	int totalRecord = 0;
	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();
		
		while(rs.next()) {
			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?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?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" />
<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='board_write1.jsp'">쓰기</button>
		</div>
	</div>
</div>
<!--//하단 디자인 -->

</body>
</html>
int totalRecord = 0;

// 커서를 맨 마지막행으로 이동
		rs.last();
		// 데이터 개수가 나옴
		totalRecord = rs.getRow();
		rs.beforeFirst();

게시물 건수를 계산하기 위해 위 구문을 이용하여 커서를 게시물 맨 아래로 보낸 뒤 위로 올라오면서 갯수를 새면서 올라온다. 그 해당 데이터를 건수에 출력하는 코드다

기존 위에서 아래로 가는 프로세스를 커서를 아래로 옮기고 위로 올라오는 구조로 짯다

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

</body>
</html>

boardEx01.emot_board1.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 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으로해서 작성 / 브라우저에서 소스보기 하면 값 확인가능 -->
		<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'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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_board1.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>");
%>

boardEx01.emot_board1.board_modify

<%@ 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 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[] {"", ""};
			}
			emot = rs.getString("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_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 %>" />
		<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>ot41.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'">목록</button>
					<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?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_board1.board_modify_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");

	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';");
	} 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>");
%>

 

반응형

댓글