DoR@Hee의 끄적끄적

JSP 글 수정 만들기 본문

개발/WEB개발

JSP 글 수정 만들기

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


VIEW - board_modify_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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8");%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style2.css?ver=1.2">
        <script charset="utf-8" type="text/javascript" src="Check.js"></script>
        <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">
    </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" />
        <form action="board_modify.do" method="get">
            <input type=hidden name="bId" value="${content.bId}">     
        <div id="board_modify_content">
        
            <table id="borad_modify">
                <span id="m_writer_font">글 수정하기</span>
                <thead>
                    <tr>
                        <td>
                            <span>제 목</span>
                        </td>
                        <td>
                            <input type="text" id="mtitle" name="bTitle" value="${content.bTitle}">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span id="mnickname">작성자</span>
                        </th>
                        <th>
                        <div id="mwriter">${content.bNickname}</div>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                             <span id="nwrite_box_font">내용</span>
                         </td>
                         <td>
                             <textarea name="bContent" maxlength="2048" cols="70%" rows="15" id=modify_box>${content.bContent}</textarea>
                         </td>
                    </tr>
                </tbody>
            </table>
            <button type="submit" id ="write_btn">글 수정</button>
            <div class="both"></div>
        </div>
       </form>
    </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
    public void board_modify(String bId, String bTitle, String bContent) {
        Connection con = null;
        PreparedStatement pstmt = null;
        
        try {
            Class.forName(driver);
            String query = "update board set bTitle = ?, bContent = ? where bId = ?"
            con = DriverManager.getConnection(url, user, password);
            pstmt = con.prepareStatement(query);
            pstmt.setString(1, bTitle);
            pstmt.setString(2, bContent);
            pstmt.setInt(3, Integer.parseInt(bId));
            pstmt.executeUpdate();
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(pstmt != null) pstmt.close();
                if(con != null) con.close();
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        }
        
}
 
cs

COMMAND 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.javalec.ex.command;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.javalec.ex.dao.BDao;
 
public class BModifyCommand implements BCommand{
    
    public void execute(HttpServletRequest request, HttpServletResponse response) {
        String bId = request.getParameter("bId");
        String bTitle = request.getParameter("bTitle");
        String bContent = request.getParameter("bContent");
        
        BDao dao = new BDao();
        dao.board_modify(bId,bTitle,bContent);
    }
 
}
 
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_modify.do")) {
            command = new BModifyCommand();
            command.execute(request, response);
            viewPage="board_content_view.do";
        }
        
        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