DoR@Hee의 끄적끄적

JSP 게시판 글 쓰기 만들기 본문

개발/WEB개발

JSP 게시판 글 쓰기 만들기

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

ViEW - board_write.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
<%@ 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">
        <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>
            <div>
                <jsp:include page="header.jsp" flush="false" />
            </div>
        </header>
        <jsp:include page="aside_left.jsp" flush="false" />
        <jsp:include page="aside_right.jsp" flush = "false" />
        <form action="board_write.do" method="get">
        <div id="board_write_content">
            <table id="borad_write">
                <thead>
                    <tr>
                        <th>
                            <span id="writer_font">글 쓰기</span>
                        </th>
                    </tr>
                    <tr>
                        <th>
                            <span>제 목</span><input type="text" id="title" name="bTitle">
                        </th>
                    </tr>
                    <tr>
                        <th>
                            <span>작성자</span><input type=text maxlength="10" id="writer" name="bNickname">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                         <span id="write_box_font">내용</span><textarea name="bContent" maxlength="2048" cols="70%" rows="15" id=write_box></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
    public void board_write(String bNickname, String bTitle, String bContent) {
        Connection con = null;
        PreparedStatement pstmt = null;
        String query = "insert into board (bId, bNickname, bTitle, bContent, bHit, bGroup, bStep, bIndent) values (board_seq.nextval, ?, ?, ?, 0, board_seq.currval, 0, 0 )";
        try {
        Class.forName(driver);
        con = DriverManager.getConnection(url, user, password);
        pstmt = con.prepareStatement(query);
        pstmt.setString(1, bNickname);
        pstmt.setString(2, bTitle);
        pstmt.setString(3, bContent);
        
        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


Controller 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    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_write_view.do")) {
            viewPage = "board_write_view.jsp";
        } else if(con.equals("/board_write.do")) {
            command = new BWriteCommand();
            command.execute(request,response);
            viewPage = "board_list.do";
        }
        
        RequestDispatcher dispatcher = request.getRequestDispatcher(viewPage);
        dispatcher.forward(request, response);
        
    }
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.*;
 
public class BWriteCommand implements BCommand {
        public void execute(HttpServletRequest request, HttpServletResponse respone) {
            
            String bNickname = request.getParameter("bNickname");
            String bTitle = request.getParameter("bTitle");
            String bContent = request.getParameter("bContent");
            
            BDao dao = new BDao();
            
            dao.board_write(bNickname, bTitle, bContent);
        }
}
 
cs




글쓰기 버튼(board_write.do) > 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