JSP 4일차 게시판 초안

RPBoardList.jsp

<%@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>

<center>
<h2>Content List</h2>

<table cellpadding="5" bgcolor="#AFE0FF" width="400" >
<tr>
<td>No.</td>
<td>Title</td>
<td>ID</td>
<td>Date</td>
<td>Hits</td>
</tr>

<%
RPBoardDAO rdao = new RPBoardDAO();
RPBoardBean rbean = new RPBoardBean();

Vector<RPBoardBean> vector = rdao.getAllContents();

for(int i=0; i<vector.size(); i++)
{
rbean = vector.get(i);
%>

<tr bgcolor="D4F4FA">
<td><%=rbean.getNo()%></td>
<td>
<a href="ContentSelect.jsp?no=<%=vector.get(i).getNo()%>">
<%=rbean.getSubject()%>
</a>
</td>
<td><%=rbean.getWriter()%></td>
<td><%=rbean.getDay()%></td>
<td><%=rbean.getHit()%></td>
</tr>

<%
}
%>
</table>

<br>
<a href = "RPBoardWrite.jsp">Write</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>

<center>
<h2>RPBoard Write</h2>

<form action="RPBoardWriteProc.jsp" method="post">
<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">
<input type="text" name="subject" size="50">
</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>
<input type="hidden" name="ref" value="1">
<input type="hidden" name="re_level" value="1">
<input type="hidden" name="re_step" value="1">

</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('ContentReply.jsp?no=<%=no%>')">
<input type="submit" value="Modify">
<input type="button" value="Delete" onclick="window.location.replace('ContentDelete.jsp?no=<%=no%>')">
</tr>
</table>
<input type="hidden" name="no" value=<%=rbean.getNo()%>>
</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>

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;

public void con()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
}
catch(Exception e)
{
}
}

public Vector<RPBoardBean> getAllContents()
{
Vector<RPBoardBean> vector = new Vector<>();

RPBoardBean rbean;

try
{
this.con();
String sql = "SELECT * from RPBoard order by no desc";

ps = con.prepareStatement(sql);
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.setDay(rs.getDate(10));
rbean.setHit(rs.getInt(11));

vector.add(rbean);
}

con.close();
ps.close();
rs.close();
}
catch(Exception e)
{
}

return vector;
}

public void writeContent(RPBoardBean content)
{
try
{
this.con();

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, 0);
ps.setInt(7, 0);
ps.setInt(8, 0);
ps.executeUpdate();

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).trim());
rbean.setContent(rs.getString(5));
rbean.setDay(rs.getDate(10));
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)
{
System.out.println(rbean.getPassword());

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;
}
}

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;
}
}


result)







댓글 없음: