JSP [ Controller ]

양혜정·2024년 4월 27일
0

javascript_web

목록 보기
69/81

Controller

  • doGet, doPost method 방식 확인
String method = request.getMethod();

Dispatcher

  • 연결해주기
  • 보안상 문제로 WEB-INF 에 넣어주어야한다.
RequestDispatcher dispatcher = request.getRequestDispatccher
	("/WEB-INF/~~~");
dispatcher.forward(request, response)

DTO(VO) 이용

  • submmit 되어져온 데이터를 받아 DB 로 보낸다.

작성한 데이터 받기

String 변수명 = request.getParameter("name명");
String 배열명[] = request.getParameterValues("name명");

작성한 데이터 DTO 에 넣기

DTO명 변수명 = new DTO명();
변수명.setName명(작성한데이터에 대한 변수명);

DTO 값들 DB에 insert 해주기

=> Controller
try{
	int n = dao.Method(DTO가 담긴 변수명);
    if(n==1){
    	pathname = "정상입력경로";
    }
} catch(SQLException e) {
	pathname = "SQL 오류났을 경우 화면경로";
}
RequestDispatcher dispatcher =request.getRequestDispatcher(pathname);
dispatcher.forward(request,response);

=> DAO_imple
public int Method(DTO명 변수명) throws SQLException{
	int n = 0;
    try{
    	String sql = " insert into 테이블명(seq, 컬럼명, 컬럼명...) "
        		+ " values(시퀀스명.nextval, ?, ?, ...)";
    pstmt = conn.prepareStatement(sql);
    pstmt.setString(1,dto변수명.getName명());
    n = pstmt.executeUpdate();
    } finally{
    	close();
    }
    return n;
}	// end of ~~~ -------------------

jsp name 명, DTO Field 명, DB 컬럼명 모두 일치하여야 한다.


정리

  • JSPServletBegin -> chap05.oracle.controller
    -> PersonRegister_01.java

  • JSPServletBegin -> chap05.oracle.domain
    -> PersonDTO_02.java

  • JSPServletBegin -> chap05.oracle.model
    -> PersonDAO_03.java, PersonDAO_imple_04.java

0개의 댓글

관련 채용 정보