AR삽질러

JSP 개인프로젝트(9) - 게시판만들기(게시글내용보기) 본문

JAVA/JSP

JSP 개인프로젝트(9) - 게시판만들기(게시글내용보기)

아랑팡팡 2023. 2. 28. 22:10
728x90

https://arang95.tistory.com/57

 

JSP 개인프로젝트(8) - 게시판만들기(게시글목록)

https://arang95.tistory.com/56 JSP 개인프로젝트(7) - singleton적용, 게시판만들기 https://arang95.tistory.com/43 JSP 개인프로젝트(6) - 회원탈퇴 https://arang95.tistory.com/42 JSP 개인프로젝트(5) - 회원정보수정 https://ara

arang95.tistory.com

지난시간에는 게시판구현과 게시판데이터입력 전송기능 게시판글 목록을 출력을 구현했다.

이번시간에는 입력한 게시판의 글을 볼수 있도록 게시글을 클릭했을때 출력하는 페이지를 구현해보겠다..

 

1. 글 내용 화면 작성

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="boardone.BoardDAO" %>
<%@ page import="boardone.BoardVO" %>
<%@ page import="java.util.List" %>
<%@ page import="java.text.SimpleDateFormat" %>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="../css/bootstrap.css">
	<link rel="stylesheet" href="../css/custom.css">
	<title>글내용보기</title>
	<script type="text/javascript" src="script.js"></script>
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
	<script src="../js/bootstrap.js"></script>
</head>
<%
	int num = Integer.parseInt(request.getParameter("num"));
	String pageNum = request.getParameter("pageNum");
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	try{
		BoardDAO dbPro = BoardDAO.getInstance();
		BoardVO article = dbPro.getArticle(num);
		int ref = article.getRef();
		int step = article.getStep();
		int depth = article.getDepth();
%>
<body>
	<%
		String id = (String)session.getAttribute("id");
	%>
	<nav class="navbar navbar-default">
	 <div class="navbar-header">
	  <button type="button" class="navbar-toggle collapsed"
	  	data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
	  	aria-expanded="false">
		 	<span class="icon-bar"></span>
		 	<span class="icon-bar"></span>
		 	<span class="icon-bar"></span>
		 </button>
		 <a class="navbar-brand" href="../memberone/main.jsp">AR 웹페이지</a>
		</div>
		<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
		 <ul class="nav navbar-nav">
		  <li class="active"><a href="../memberone/main.jsp">메인</a>
		   <li class="active"><a href="../boardone/writeForm.jsp">게시판</a>
		 </ul>
		 <%
		 	if(id == null){
		 %>
		 <ul class="nav navbar-nav navbar-right">
		  <li class="dropdown">
		   <a href="#" class="dropdown-toggle"
		   	data-toggle="dropdown" role="button" aria-haspopup="true"
		   	aria-expanded="false">접속하기<span class="caret"></span>
		   </a>
		   <ul class="dropdown-menu">
		   	<li><a href="../memberone/login.jsp">로그인</a></li>
		   	<li><a href="../memberone/regForm.jsp">회원가입</a></li>
		   </ul>
		  </li>
		 </ul>
		 <%
		 	}
		 %>
		</div>
	</nav>
	<div class="container">
	  <table class="table table-bordered table-hover" style="text-align: center; border: 1px solid #ddddddd">
	   <thead>
	    <tr>
	     <th colspan="4"><h4>글내용</h4></th>
	    </tr>
		<tbody>
		
		<tr>
	      <td style="width:125px;" align="center"><h5>글번호</h5></td>
	      <td style="width:125px;" align="center"><h5><%=article.getNum() %></h5></td>
	      <td style="width:125px;" align="center"><h5>조회수</h5></td>
	      <td style="width:125px;" align="center"><h5><%=article.getReadcount() %></h5></td>
	    </tr>
	    <tr>
	      <td align="center" style="width:125px;" align="center"><h5>작성자</h5></td>
	      <td align="center" style="width:375px;"><h5><%=article.getWriter() %></h5></td>
	      <td align="center"style="width:125px;"><h5>작성일</h5></td>
	      <td align="center" style="width:125px;"><h5><%=article.getRegdate() %></h5></td>
	    </tr>
	    <tr>
	      <td align="center" style="width:125px;" align="center"><h5>글제목</h5></td>
	      <td align="center" style="width:375px;" colspan="3"><h5><%=article.getSubject() %><h5></td>
	    </tr>
	    <tr>
	      <td align="center" style="width:125px;"><h5>글내용</h5></td>
	      <td align="left" style="width:375px;" colspan="3"><h5><%=article.getContent() %></h5></td>
	    </tr>
	    
	    <tr>
			<td colspan="4" align="center">
			<input class="btn btn-primary" type="button" value="게시글 수정" onClick="document.location.href='updateForm.jsp?num=<%=article.getNum()%>&pageNum=<%=pageNum%>'">&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="btn btn-primary" type="button" value="게시글 삭제" onClick="document.location.href='deleteForm.jsp?num=<%=article.getNum() %>&pageNum=<%=pageNum %>'">&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="btn btn-primary" type="button" value="게시글 목록" onClick="document.location.href='list.jsp?pageNum=<%=pageNum %>'">
			</td>		
		</tr>		
	     
	     
	</tbody>
	
	<%
		}catch(Exception e){}
	%>
	  </thead>
	 </table>
	</div>
</body>
</html>

 

2. 게시판 글내용검색DAO

public BoardVO getArticle(int num) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		BoardVO article = null;
		try {
			conn = ConnUtil.getcConnection();
			pstmt = conn.prepareStatement("update board set readcount = readcount+1 where num = ?");
			pstmt.setInt(1, num);
			pstmt = conn.prepareStatement("select * from board where num = ?");
			pstmt.setInt(1, num);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				article = new BoardVO();
				article.setNum(rs.getInt("num"));
				article.setWriter(rs.getString("writer"));
				article.setEmail(rs.getString("email"));
				article.setSubject(rs.getString("subject"));
				article.setPass(rs.getString("pass"));
				article.setRegdate(rs.getTimestamp("regdate"));
				article.setReadcount(rs.getInt("readcount"));
				article.setRef(rs.getInt("ref"));
				article.setStep(rs.getInt("step"));
				article.setDepth(rs.getInt("depth"));
				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;
	}

 

. 구현화면

1. 게시판화면

2. 글쓰기화면

3. 게시글 글내용화면

 

다음시간에는 게시글 수정 삭제 조회수 증가를 구현해보겠다..

728x90
반응형
LIST