<%@page import="java.util.Vector"%>
<%@page import="RPBoardPac.RPBoardBean"%>
<%@page import="RPBoardPac.RPBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Content List</title>
</head>
<body>
<%
int pageSize = 10;
String pageNum = request.getParameter("pageNum");
int count = 0;
int number = 0;
if(pageNum == null)
{
pageNum = "1";
}
int currentPage = Integer.parseInt(pageNum);
RPBoardDAO rdao = new RPBoardDAO();
count = rdao.getAllCount();
int startRow = (currentPage-1)*pageSize+1;
int endRow = currentPage*pageSize;
if(count > 0)
{
Vector<RPBoardBean> vector = rdao.getAllContents(startRow, endRow);
number = count-(currentPage-1)*pageSize;
%>
<center>
<h2>Content List</h2>
<table cellpadding="10" bgcolor="#AFE0FF">
<tr>
<td>No.</td>
<td width="300">Title</td>
<td>ID</td>
<td>Date</td>
<td>Hits</td>
</tr>
<%
RPBoardBean rbean = new RPBoardBean();
for(int i=0; i<vector.size(); i++)
{
rbean = vector.get(i);
%>
<tr bgcolor="D4F4FA">
<td><%=number--%></td>
<td align="left">
<%
if(rbean.getRe_level()>0)
{
for(int j=0; j<rbean.getRe_level(); j++)
{
out.print(" ");
}
}
%>
<a href="ContentSelect.jsp?no=<%=rbean.getNo()%>">
<%=rbean.getSubject()%>
</a>
</td>
<td><%=rbean.getWriter()%></td>
<td><%=rbean.getDay()%></td>
<td><%=rbean.getHit()%></td>
</tr>
<%
}
}
%>
</table>
<br>
<a href = "RPBoardWrite.jsp">
<img src="http://3.bp.blogspot.com/
-QZf9TwaQ_MM/UeUCmjljYTI/AAAAAAAAAnM/SyGeGttS4uc/s1600/write.jpg"></a>
<br><br>
<%
if(count>0)
{
int pageCount = count/pageSize+(count%pageSize==0 ? 0 : 1);
int startPage = 1;
if(currentPage%10 != 0)
{
startPage = (int)(currentPage/10)*10+1;
}
else
{
startPage = ((int)(currentPage/10)-1)*10+1;
}
int pageBlock = 10;
int endPage = startPage+pageBlock-1;
if(endPage>pageCount)
{
endPage = pageCount;
}
if(startPage>10)
{
%>
<a href="RPBoardList.jsp?pageNum=<%=startPage-10%>">[prev]</a>
<%
}
for(int j=startPage; j<=endPage; j++)
{
%>
<a href="RPBoardList.jsp?pageNum=<%=j%>"><%=j%></a>
<%
}
if(endPage<pageCount)
{
%>
<a href="RPBoardList.jsp?pageNum=<%=startPage+10%>">[next]</a>
<%
}
}
%>
</center>
</body>
</html>
RPBoardWrite.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>RPBoard Write</title>
</head>
<body>
<%
int no = 0;
int ref = 1;
int re_level = 0;
int re_step = 0;
if(request.getParameter("no") != null)
{
no = Integer.parseInt(request.getParameter("no"));
ref = Integer.parseInt(request.getParameter("ref"));
re_level = Integer.parseInt(request.getParameter("re_level"));
re_step = Integer.parseInt(request.getParameter("re_step"));
}
%>
<center>
<h2>RPBoard Write</h2>
<form action="RPBoardWriteProc.jsp" method="post">
<input type="hidden" name="no" value="<%=no%>">
<input type="hidden" name="ref" value="<%=ref%>">
<input type="hidden" name="re_level" value="<%=re_level%>">
<input type="hidden" name="re_step" value="<%=re_step%>">
<table width="500" border="0" cellpadding="5" cellspacing="5" bgcolor="#AFE0FF">
<tr>
<td width="70" align="center">Writer</td>
<td width="330" bgcolor="D4F4FA">
<input type="text" name="writer" size="20">
</td>
</tr>
<tr>
<td width="70" align="center">Subject</td>
<td width="330" bgcolor="D4F4FA">
<%
if(request.getParameter("no")==null)
{
%>
<input type="text" name="subject" size="50">
<%
}
else
{
%>
<input type="text" name="subject" size="50" value=" re: ">
<%
}
%>
</td>
</tr>
<tr>
<td width="70" align="center">Email</td>
<td width="330" bgcolor="D4F4FA">
<input type="text" name="email" size="50">
</td>
</tr>
<tr>
<td width="70" align="center">Content</td>
<td width="330" bgcolor="D4F4FA">
<textarea name="content" rows="13" cols="50">
</textarea>
</td>
</tr>
<tr>
<td width="70" align="center">Password</td>
<td width="330" bgcolor="D4F4FA">
<input type="password" name="password" size="10">
</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="Write">
<input type="reset" value="Reset">
<input type="button" value="List" onclick="window.location='RPBoardList.jsp'">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>RPBoard Write</title>
</head>
<body>
<%
int no = 0;
int ref = 1;
int re_level = 0;
int re_step = 0;
if(request.getParameter("no") != null)
{
no = Integer.parseInt(request.getParameter("no"));
ref = Integer.parseInt(request.getParameter("ref"));
re_level = Integer.parseInt(request.getParameter("re_level"));
re_step = Integer.parseInt(request.getParameter("re_step"));
}
%>
<center>
<h2>RPBoard Write</h2>
<form action="RPBoardWriteProc.jsp" method="post">
<input type="hidden" name="no" value="<%=no%>">
<input type="hidden" name="ref" value="<%=ref%>">
<input type="hidden" name="re_level" value="<%=re_level%>">
<input type="hidden" name="re_step" value="<%=re_step%>">
<table width="500" border="0" cellpadding="5" cellspacing="5" bgcolor="#AFE0FF">
<tr>
<td width="70" align="center">Writer</td>
<td width="330" bgcolor="D4F4FA">
<input type="text" name="writer" size="20">
</td>
</tr>
<tr>
<td width="70" align="center">Subject</td>
<td width="330" bgcolor="D4F4FA">
<%
if(request.getParameter("no")==null)
{
%>
<input type="text" name="subject" size="50">
<%
}
else
{
%>
<input type="text" name="subject" size="50" value=" re: ">
<%
}
%>
</td>
</tr>
<tr>
<td width="70" align="center">Email</td>
<td width="330" bgcolor="D4F4FA">
<input type="text" name="email" size="50">
</td>
</tr>
<tr>
<td width="70" align="center">Content</td>
<td width="330" bgcolor="D4F4FA">
<textarea name="content" rows="13" cols="50">
</textarea>
</td>
</tr>
<tr>
<td width="70" align="center">Password</td>
<td width="330" bgcolor="D4F4FA">
<input type="password" name="password" size="10">
</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="Write">
<input type="reset" value="Reset">
<input type="button" value="List" onclick="window.location='RPBoardList.jsp'">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
RPBoardWriteProc.jsp
<%@page import="RPBoardPac.RPBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>RPBoard Write</title>
</head>
<body>
<jsp:useBean id="content" class="RPBoardPac.RPBoardBean"></jsp:useBean>
<jsp:setProperty property="*" name="content"/>
<%
RPBoardDAO rdao = new RPBoardDAO();
rdao.writeContent(content);
response.sendRedirect("RPBoardList.jsp");
%>
</body>
</html>
ContentSelect.jsp
<%@page import="RPBoardPac.RPBoardBean"%>
<%@page import="RPBoardPac.RPBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Content Select</title>
</head>
<body>
<center>
<h2>Content Select</h2>
<%
int no = Integer.parseInt(request.getParameter("no"));
RPBoardDAO rdao = new RPBoardDAO();
RPBoardBean rbean = rdao.viewContent(no);
rdao.increaseHit(no, rbean.getHit());
%>
<form action="ContentModify.jsp" method="post">
<table border="0" cellpadding="5" cellspacing="5" bgcolor="#AFE0FF">
<tr align="center">
<td>No</td>
<td width="330" bgcolor="D4F4FA">
<%=rbean.getNo()%>
</td>
</tr>
<tr align="center">
<td width="70" align="center">Writer</td>
<td width="330" bgcolor="D4F4FA">
<%=rbean.getWriter()%>
</td>
</tr>
<tr>
<td width="70" align="center">Subject</td>
<td width="330" bgcolor="D4F4FA">
<input type="text" name="subject" size="50" value="<%=rbean.getSubject()%>">
</td>
</tr>
<tr>
<td width="70" align="center">Password</td>
<td width="330" bgcolor="D4F4FA">
<input type="password" name="password" size="10">
</td>
</tr>
<tr align="left">
<td width="70" align="center">Content</td>
<td width="330" bgcolor="D4F4FA">
<textarea name="content" rows="13" cols="50"><%=rbean.getContent()%>
</textarea>
</td>
</tr>
<tr align="left">
<td colspan=4 align="center">
<input type="button" value="Reply"
onclick="window.location.replace('RPBoardWrite.jsp?no=<%=rbean.getNo()%>&ref=<%=rbean.getRef()%>&re_step=<%=rbean.getRe_step()%>&re_level=<%=rbean.getRe_level()%>')">
<input type="submit" value="Modify">
<input type="button" value="Delete"
onclick="window.location.replace('ContentDelete.jsp?no=<%=no%>')">
<input type="button" value="List"
onclick="window.location='RPBoardList.jsp'">
</tr>
</table>
<input type="hidden" name="no" value="<%=no%>">
</form>
</center>
</body>
</html>
ContentModify.jsp
<%@page import="RPBoardPac.RPBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Content Modify</title>
</head>
<body>
<%
request.setCharacterEncoding("euc-kr");
%>
<jsp:useBean id="content" class="RPBoardPac.RPBoardBean"></jsp:useBean>
<jsp:setProperty property="*" name="content"/>
<%
RPBoardDAO rdao = new RPBoardDAO();
rdao.modifyContent(content);
response.sendRedirect("RPBoardList.jsp");
%>
</body>
</html>
ContentDelete.jsp
<%@page import="RPBoardPac.RPBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Content Delete</title>
</head>
<body>
<%
request.setCharacterEncoding("euc-kr");
%>
<jsp:useBean id="content" class="RPBoardPac.RPBoardBean"></jsp:useBean>
<jsp:setProperty property="*" name="content"/>
<%
RPBoardDAO rdao = new RPBoardDAO();
rdao.deleteContent(content);
response.sendRedirect("RPBoardList.jsp");
%>
</body>
</html>
RPBoardBean.java
package RPBoardPac;
import java.sql.Date;
public class RPBoardBean
{
private int no;
private String writer;
private String password;
private String subject;
private String content;
private String email;
private int ref;
private int re_level;
private int re_step;
private Date day;
private int hit;
public int getNo()
{
return no;
}
public void setNo(int no)
{
this.no = no;
}
public String getWriter()
{
return writer;
}
public void setWriter(String writer)
{
this.writer = writer;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getSubject()
{
return subject;
}
public void setSubject(String subject)
{
this.subject = subject;
}
public String getContent()
{
return content;
}
public void setContent(String content)
{
this.content = content;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public int getRef()
{
return ref;
}
public void setRef(int ref)
{
this.ref = ref;
}
public int getRe_level()
{
return re_level;
}
public void setRe_level(int re_level)
{
this.re_level = re_level;
}
public int getRe_step()
{
return re_step;
}
public void setRe_step(int re_step)
{
this.re_step = re_step;
}
public Date getDay()
{
return day;
}
public void setDay(Date day)
{
this.day = day;
}
public int getHit()
{
return hit;
}
public void setHit(int hit)
{
this.hit = hit;
}
}
RPBoardDAO.java
package RPBoardPac;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import RPBoardPac.RPBoardBean;
public class RPBoardDAO
{
String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;
int count=0;
public void con()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
}
catch(Exception e)
{
}
}
public Vector<RPBoardBean> getAllContents(int start, int end)
{
Vector<RPBoardBean> vector = new Vector<>();
RPBoardBean rbean;
try
{
this.con();
String sql = "SELECT * from (SELECT A.* , "
+"Rownum Rnum from (SELECT * from RPBoard order by ref desc, re_step)A)"
+"where Rnum > ? and Rnum <= ?";
ps = con.prepareStatement(sql);
ps.setInt(1, start-1);
ps.setInt(2, end);
rs = ps.executeQuery();
while(rs.next())
{
rbean = new RPBoardBean();
rbean.setNo(rs.getInt(1));
rbean.setSubject(rs.getString(4));
rbean.setWriter(rs.getString(2));
rbean.setRe_level(rs.getInt(8));
rbean.setDay(rs.getDate(10));
rbean.setHit(rs.getInt(11));
vector.add(rbean);
}
con.close();
ps.close();
rs.close();
}
catch(Exception e)
{
}
return vector;
}
public int getAllCount()
{
try
{
this.con();
String sql = "SELECT count(*) from RPBoard";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
rs.close();
con.close();
ps.close();
}
catch(Exception e)
{
}
return count;
}
public void writeContent(RPBoardBean content)
{
try
{
this.con();
int no = content.getNo();
int ref = content.getRef();
int re_level = content.getRe_level();
int re_step = content.getRe_step();
if(no != 0 )
{
String sql = "UPDATE RPBoard set re_step=re_step+1"
+"where ref=? and re_step>?";
ps = con.prepareStatement(sql);
ps.setInt(1, ref);
ps.setInt(2, re_step);
ps.executeUpdate();
re_level += 1;
re_step += 1;
}
else
{
String sql = "SELECT max(ref) from RPBoard";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
if(rs.next())
{
ref = rs.getInt(1)+1;
}
else
{
ref = 1;
}
re_level = 0;
re_step = 0;
}
String sql = "INSERT into RPBoard values(rpboard_No.nextval,"
+"?, ?, ?, ?, ?, ?, ?, ?, sysdate, 0)";
ps = con.prepareStatement(sql);
ps.setString(1, content.getWriter());
ps.setString(2, content.getPassword());
ps.setString(3, content.getSubject());
ps.setString(4, content.getContent());
ps.setString(5, content.getEmail());
ps.setInt(6, ref);
ps.setInt(7, re_level);
ps.setInt(8, re_step);
ps.executeUpdate();
rs.close();
con.close();
ps.close();
}
catch(Exception e)
{
}
}
public RPBoardBean viewContent(int no)
{
RPBoardBean rbean = null;
try
{
this.con();
rbean = new RPBoardBean();
String sql = "SELECT * from RPBoard where no=?";
ps = con.prepareStatement(sql);
ps.setInt(1, no);
rs = ps.executeQuery();
rs.next();
rbean.setNo(rs.getInt(1));
rbean.setWriter(rs.getString(2));
rbean.setSubject(rs.getString(4));
rbean.setContent(rs.getString(5));
rbean.setDay(rs.getDate(10));
rbean.setRef(rs.getInt(7));
rbean.setRe_level(rs.getInt(8));
rbean.setRe_step(rs.getInt(9));
rbean.setHit(rs.getInt(11));
ps.close();
rs.close();
con.close();
}
catch(Exception e)
{
}
return rbean;
}
public void increaseHit(int no, int hit)
{
try
{
this.con();
String sql = "UPDATE RPBoard set hit=? where no=?";
ps = con.prepareStatement(sql);
ps.setInt(1, hit+1);
ps.setInt(2, no);
ps.executeUpdate();
con.close();
ps.close();
}
catch(Exception e)
{
}
}
public void modifyContent(RPBoardBean rbean)
{
try
{
this.con();
String sql = "UPDATE RPBoard set subject=?, content=? where no=?";
ps = con.prepareStatement(sql);
ps.setString(1, rbean.getSubject());
ps.setString(2, rbean.getContent());
ps.setInt(3, rbean.getNo());
ps.executeUpdate();
con.close();
ps.close();
}
catch(Exception e)
{
}
}
public void deleteContent(RPBoardBean rbean)
{
try
{
this.con();
String sql = "DELETE from RPBoard where no=?";
ps = con.prepareStatement(sql);
ps.setInt(1, rbean.getNo());
ps.executeUpdate();
con.close();
ps.close();
}
catch(Exception e)
{
}
}
public boolean passworkdCheck(RPBoardBean rbean, String password)
{
String DBpassword = null;
try
{
this.con();
String sql = "SELECT password from RPBoard where no=?";
ps = con.prepareStatement(sql);
ps.setInt(1, rbean.getNo());
ps.executeUpdate();
DBpassword = rs.getString(1);
con.close();
ps.close();
}
catch(Exception e)
{
}
if(DBpassword.equals(password))
return true;
else
return false;
}
}
댓글 없음:
댓글 쓰기