모델1 게시판 - 글입력 구현
http://injava.tistory.com/9 방법과의 차이점(장단점)을 학습
boardAddForm.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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>BOARD ADD</title> </head> <body> <h1>BOARD ADD</h1> <form action="<%=request.getContextPath()%>/board/boardAddAction.jsp" method="post"> <div>boardPw : </div> <div><input name="boardPw" id="boardPw" type="password"/></div> <div>boardTitle : </div> <div><input name="boardTitle" id="boardTitle" type="text"/></div> <div>boardContent : </div> <div><textarea name="boardContent" id="boardContent" rows="5" cols="50"></textarea></div> <div>boardName : </div> <div><input name="boardUser" id="boardUser" type="text"/></div> <div> <input type="submit" value="글입력"/> <input type="reset" value="초기화"/> </div> </form> </body> </html> | cs |
boardAddAction.jsp :
모델1 방식에서는 jsp파일에서 DB table을 접근하는 비지니스코드를 구현하지 않고, BoardDao클래스의 메서드로 구현해 놓고 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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import="java.sql.*" %> <%@ page import="service.*" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title></title> </head> <body> <% request.setCharacterEncoding("euc-kr"); String boardPw = request.getParameter("boardPw"); System.out.println("param boardPw:"+boardPw); String boardTitle = request.getParameter("boardTitle"); System.out.println("param boardTitle:"+boardTitle); String boardContent = request.getParameter("boardContent"); System.out.println("param boardContent:"+boardContent); String boardUser = request.getParameter("boardUser"); System.out.println("param boardUser:"+boardUser); Board board = new Board(); board.setBoardPw(boardPw); board.setBoardTitle(boardTitle); board.setBoardContent(boardContent); board.setBoardUser(boardUser); BoardDao boardDao = new BoardDao(); int rowCount = boardDao.insertBoard(board); response.sendRedirect(request.getContextPath()+"/board/boardList.jsp"); %> </body> </html> | cs |
'P. 자바 미니 프로젝트 > 모델1 게시판' 카테고리의 다른 글
P.2.6 모델1 게시판 만들기6 - 글수정 (2) | 2016.11.30 |
---|---|
P.2.5 모델1 게시판 만들기5 - 글삭제 (0) | 2016.11.30 |
P.2.4 모델1 게시판 만들기4 - 글내용 (0) | 2016.11.30 |
P.2.3 모델1 게시판 만들기3 - 글목록 (2) | 2016.11.30 |
P.2.1 모델1 게시판 만들기1 - DAO클래스 (1) | 2016.11.30 |