- 요청의 처리는 BoardServlet.java, 요청에 따른 model의 객체 생성은 ActionFactory.java 에서 수행
- 비즈니스 계층의 모든 class는 Action 인터페이스를 상속받는다.
- DAO, View 부분은 이전의 예제에서 단순히 분리 및 관리한다.
- 요청은 쿼리스트링 방식으로 전달하며, command 파라미터(문자열)을 이용하여 요청 처리
※해당 실습은 교제를 참고함
※DTO : BoardVO
- DB 테이블 설계 참고
※DAO :
public List<Board VO> selectAllBoard() : 테이블 전체 조회
public void inserBoard(BoardVO vo) : 테이블 데이터 삽입
public void updateReadCount(String num) : 게시물 조회 시 조회수 1씩 증가
public BoardVO selectOneBoardByNum(String num) : 게시물 단일 조회(게시물 조회, 삭제, 갱신에 사용)
public void updateBoard(BoardVO vo) : 게시물 갱신
public BoardVO checkPassWord(String pass, String num) : 게시물 갱신, 삭제시, 입력 받은 비밀번호 일치 여부 확인 및 해당 게시물 정보 반환
public deleteBoard(String num) : 게시물 삭제
※ 교제 실습 추가 사항
- BoardWriteAction 의 테이블 데이터 추가 시, 새로고침(F5) 수행 시 중복 데이터가 추가되는 현상 발생 : double submit
원인 : BoardWriteAction 동작 수행 시 사용된 request 객체의 재사용 및 재실행
-> request 객체의 Life cycle을 이용한 해결 방법 수행
해당 현상의 수정을 위해
new BoardListAction().excute(request, response);
객체 생성 후 해당 객체를 이용한 Forward 가 아닌, redirect 방식을 사용
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 | package com.seayon.controller.action; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.seayon.dao.BoardDAO; import com.seayon.dto.BoardVO; public class BoardWriteAction implements Action{ @Override public void excute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // TODO Auto-generated method stub BoardVO vo = new BoardVO(); vo.setName(request.getParameter("name")); vo.setPass(request.getParameter("pass")); vo.setEmail(request.getParameter("email")); vo.setTitle(request.getParameter("title")); vo.setContent(request.getParameter("content")); BoardDAO dao = BoardDAO.getInstance(); dao.insertBoard(vo); String url = "BoardServlet?command=board_list"; // 전체 조회에 대한 command 쿼리 스트링 작성 response.sendRedirect(url); // 리다이렉션 } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String command = request.getParameter("command"); if(command==null) command = "board_list"; // 요청 값이 없는 경우, 전체 조회로 이동할 수 있게 설정 System.out.println("요청 : "+command); ActionFactory af = ActionFactory.getInstance(); //singleton 객체 생성 Action action = af.getAction(command); //command 요청 받아 if(action != null) { action.excute(request, response); } } | cs |
댓글
댓글 쓰기