public class InfoDispatchAction extends DispatchAction{
public ActionForward register(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
/*form parameter를 bean으로 받는다*/
InfoFormBean bean = new InfoFormBean();
bean.setName(request.getParameter("name"));
bean.setSex(request.getParameter("sex"));
bean.setTel(request.getParameter("tel"));
/*bean property 를 dto로 복사한다.*/
InfoDTO dto = new InfoDTO();
BeanUtils.copyProperties(dto, bean);
dto.setWdate(this.getWdate());
/*info table에 연동한다.*/
new InfoDAO().register(dto);
/*result.jsp로 포워드하기 위해 리퀘스트 영역에 dto를 binding한다*/
request.setAttribute("dto", dto);
return mapping.findForward("result");
}
public ActionForward list(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
List<InfoDTO> list = null;
list = new InfoDAO().getAllQuery();
request.setAttribute("list", list);
return mapping.findForward("list");
}
public ActionForward query(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
InfoFormBean bean = (InfoFormBean)form;
InfoDTO dto = new InfoDTO();
BeanUtils.copyProperties(dto, bean);
//쿼리된 object를 리퀘스트 영역에 바인딩 한다.
request.setAttribute("dto", new InfoDAO().getQuery(dto));
return mapping.findForward("query");
}
public ActionForward update(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
/*form parameter를 InfoFormBean으로 받는다*/
/**
* ActionForm의 역할
* Form parameter의 정보를 참조하기 위해
* ActionForm의 객체를 초기화 한다 - reset()
*
* form parameter의 정보를 받아 유효성 검사를 실시한다 - validate()
*
* 참조한 폼 정보를 form-bean에 설정된 bean으로 전달한다.
* */
InfoFormBean bean = (InfoFormBean)form;
/*bean의 객체를 Entity(DTO)로 property를 복사한다.*/
InfoDTO dto = new InfoDTO();
BeanUtils.copyProperties(dto, bean);
new InfoDAO().update(dto);
return mapping.findForward("update");
}
public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
InfoFormBean bean = (InfoFormBean)form;
/*bean의 객체를 Entity(DTO)로 property를 복사한다.*/
InfoDTO dto = new InfoDTO();
BeanUtils.copyProperties(dto, bean);
new InfoDAO().delete(dto);
return mapping.findForward("delete");
}
protected String getWdate(){
return new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
}
}
자세한 내용은 파일을 참조한다.