[10] MVC2패턴 게시판 - ④ 상세보기
--------------------------------------------/WEB-INF/CommandPro.properties 추가
/mvc2bbs/content.do=my.action.ContentAction
-------------------------------------------------------------ContentAction.java
package my.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import my.board.BoardDBBean;
import my.board.BoardDataBean;
public class ContentAction implements CommandAction {
public String requestPro(HttpServletRequest request,
HttpServletResponse response) throws Throwable{
//해당글번호
int num=Integer.parseInt(request.getParameter("num"));
//해당페이지번호
String pageNum=request.getParameter("pageNum");
//DB처리
BoardDBBean dbPro=BoardDBBean.getInstance();
//해당 글번호에 대한 해당 레코드
BoardDataBean article=dbPro.getArticle(num);
request.setAttribute("num",new Integer(num));
request.setAttribute("pageNum",new Integer(pageNum));
request.setAttribute("article",article);
return "content.jsp";
}
}
-------------------------------------------------------------BoardDBBean.java추가
//content 메소드
public class BoardDBBean{
public BoardDataBean getArticle(int num) throws Exception{
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
BoardDataBean article=null;
try{
conn=getConnection();
String sql="Update board Set readcount=readcount+1 where num=?";
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1, num);
pstmt.executeUpdate();
sql="Select * From board where num=?";
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1, num);
rs=pstmt.executeQuery();
if(rs.next()){
article=new BoardDataBean();
article.setNum(rs.getInt("num"));
article.setWriter(rs.getString("writer"));
article.setEmail(rs.getString("email"));
article.setSubject(rs.getString("subject"));
article.setPasswd(rs.getString("passwd"));
article.setReg_date(rs.getTimestamp("reg_date"));
article.setReadcount(rs.getInt("readcount"));
article.setRef(rs.getInt("ref"));
article.setRe_step(rs.getInt("re_step"));
article.setRe_level(rs.getInt("re_level"));
article.setContent(rs.getString("content"));
article.setIp(rs.getString("ip"));
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs!=null) try { rs.close(); } catch(SQLException e){}
if(pstmt!=null) try { pstmt.close(); } catch(SQLException e){}
if(conn!=null) try { conn.close(); } catch(SQLException e){}
}
return article;
}
}
-----------------------------------------------------------content.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/view/color.jspf" %>
<!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>상세보기</title>
</head>
<body bgcolor="${bodyback_c }">
<center><b>글내용보기</b></center>
<br/>
<form>
<table border="1">
<tr>
<td bgcolor="${value_c }">글번호</td>
<td>${article.num }</td>
<td bgcolor="${value_c }">조회수</td>
<td>${article.readcount }</td>
</tr>
<tr>
<td bgcolor="${value_c }">작성자</td>
<td>${article.writer }</td>
<td bgcolor="${value_c }">작성일</td>
<td>${article.reg_date }</td>
</tr>
<tr>
<td bgcolor="${value_c }">글제목</td>
<td colspan=3>${article.subject }</td>
</tr>
<tr>
<td bgcolor="${value_c }">글내용</td>
<td colspan=3>${article.content }</td>
</tr>
<tr>
<td colspan=4 bgcolor="${value_c }">
<input type="button" value="글수정"
onClick="document.location.href='/mvc2bbs/updateForm.do?num=${article.num}
&pageNum=${pageNum }'">
<input type="button" value="글삭제"
onClick="document.location.href='/mvc2bbs/deleteForm.do?num=${article.num}
&pageNum=${pageNum }'">
<input type="button" value="답변"
onClick="document.location.href='/mvc2bbs/writeForm.do?num=${article.num}
&ref=${article.ref }&re_step=${article.re_step }$re_level=${article.re_level }'">
<input type="button" value="목록"
onClick="document.location.href='/mvc2bbs/list.do?pageNum=${pageNum }'">
</td>
</tr>
</table>
</form>
</body>
</html>