DoR@Hee의 끄적끄적

JSP 글 보기 만들기 본문

개발/WEB개발

JSP 글 보기 만들기

DoR@Hee 2019. 1. 31. 17:47

VIEW - board_content_view.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import ="com.javalec.ex.dto.*" %>
<jsp:useBean id="dto" class="com.javalec.ex.dto.BDto" scope="page"></jsp:useBean>
<%request.setCharacterEncoding("EUC-KR");%>
<!DOCTYPE html>
 
<html>
    <head>
        <script charset="utf-8" type="text/javascript" src="Check.js"></script>
        <link rel="stylesheet" href="style2.css?ver=1.7">
        <link href="https://fonts.googleapis.com/css?family=Gamja+Flower&amp;subset=korean" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Mukta" rel="stylesheet">
        <script>
        function deleteOk(){
            if (confirm("정말 삭제하시겠습니까??"== true){    //확인
                location.href="board_delete.do?bId=${content.bId}"
            }else{   //취소
                return;
            }
        }
        </script>
    </head>
    <body>
        <header>
            <jsp:include page="header.jsp" flush="false" />
        </header>
        <jsp:include page="aside_left.jsp" flush="false" />
        <jsp:include page="aside_right.jsp" flush = "false" />
        <div id ="board_view_content_a">
        <div id="board_view_content">
    <form action="board_modify_view.do" method="post">
        <input type="hidden" name="bId" value="${content.bId}">
        <input type="hidden" name="bTitle" value="${content.bTitle}">
        <input type="hidden" name="bContent" value="${content.bContent}">
            <p>글 보기</p>
            <table>
                <thead>
                    <tr id="ctitle1">
                        <td class="ctitle">제목</td>
                        <td><div class="box" id="ctitle">
                        <span>${content.bTitle}</span></div></td>
                        <td></td>                 
                    </tr>
                    <tr>
                        <td class="cnickname">글쓴이</td>
                        <td><div class="box" id="nick">
                        <span>${content.bNickname}</span></div></td>
                        <td></td>
                    </tr>
                </thead>
                
                <tbody>
                    <tr>
                        <td>내용</td>
                        <td><div class="box" id="contentbox">
                        <span>${content.bContent}</span></div></td>
                        <td></td>
                    </tr>
                </tbody>
            </table>
            <a href="board_list.do"><button type="button" class="btn" id="list">목록</button></a>
             <a href="#"><button type="button" class="btn" id="delete" onclick="deleteOk();">삭제</button></a>
            <button type="submit" class="btn" id="modify">수정</button>
            <div class="clear"></div>
            </form>
           </div>
        <div id="replay_content">
            <p id="replay_font">댓글</p>
            <input type="text" placeholder="댓글 내용을 입력해 주세요.(100자 제한)" maxlength="100" id="replay">
            <button class="btn" id="repaly_btn">댓글 작성</button>
        </div>
        </div>
        <footer>
            <jsp:include page="footer.jsp" flush = "false" />
        </footer>
    </body>
</html>
cs


MODEL- BDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    public BDto board_contentView(String strId) {
        
        Hit(strId);
        
        BDto dto = null;
        Connection con= null;
        PreparedStatement pstmt = null;
        ResultSet res = null;
        
        try {
            Class.forName(driver);
            con=DriverManager.getConnection(url, user, password);
            String query = "select * from board where bId = ?";
            pstmt=con.prepareStatement(query);
            pstmt.setInt(1, Integer.parseInt(strId));
            res = pstmt.executeQuery();
            
            if(res.next()) {
                int bId = res.getInt("bId");
                String bNickname = res.getString("bNickname");
                String bTitle = res.getString("bTitle");
                String bContent = res.getString("bContent");
                Date bDate = res.getDate("bDate");
                int bHit = res.getInt("bHit");
                int bGroup = res.getInt("bGroup");
                int bStep = res.getInt("bStep");
                int bIndent = res.getInt("bIndent");
                
                dto =new BDto(bId,bNickname,bTitle,bContent,bDate,bHit,bGroup,bStep,bIndent);
            } 
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            try {
            if(res != null) res.close();
            if(pstmt != null) pstmt.close();
            if(con != null) con.close();
            } catch(Exception e2) {
                e2.printStackTrace();
            }
        }
        return dto;
    }
cs

COMMAND 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.javalec.ex.command;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.javalec.ex.dao.*;
import com.javalec.ex.dto.*;
 
public class BContentCommnad implements BCommand {
    public void execute(HttpServletRequest request, HttpServletResponse response) {
        String bId = request.getParameter("bId");
        BDao dao = new BDao();
        BDto dto = dao.board_contentView(bId);
        
        
        request.setAttribute("content", dto);
    }
}
 
cs

CONTROLLER

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    private void actiondo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        request.setCharacterEncoding("EUC-KR");
        
        String viewPage = null// 페이지 리다이렉트
        BCommand command = null// command 저장
        
        String url = request.getRequestURI(); //  ex)http://localhost/board/test.jsp >> board/test.jsp
        String conPath = request.getContextPath(); // ex) http://localhost/board/test.jsp >> /test.jsp
        String con = url.substring(conPath.length());    
    } if(con.equals("/board_content_view.do")) {
            command = new BContentCommnad();
            command.execute(request, response);
            viewPage = "board_content_view.jsp";
        }
        
        RequestDispatcher dispatcher = request.getRequestDispatcher(viewPage);
        dispatcher.forward(request, response);
        
    }
cs


글 제목 클릭 > controller > command > model > view


'개발 > WEB개발' 카테고리의 다른 글

JSP 글 수정 만들기  (0) 2019.01.31
JSP 로그아웃 만들기  (0) 2019.01.31
JSP 글 리스트 만들기  (0) 2019.01.31
JSP 게시판 글 쓰기 만들기  (0) 2019.01.31
JSP 회원가입 만들기  (0) 2019.01.31
Comments