에서 update와 delete를 추가하면서 설명. Struts1.war 파일에 추가 됨.
1. InfoFormBean.java 에서 ActionForm을 상속 받는다.
package com.myhome.info.beans;
import org.apache.struts.action.ActionForm;
@SuppressWarnings("serial")
public class InfoFormBean extends ActionForm{
private int num;
private String name;
private String sex;
private String tel;
...... 생략 ......
2. struts-config.xml에서 form-bean을 설정한다.
<!-- Form Bean Definitions -->
<!-- form으로 들어오는 데이터를 bean객체에 담는다 -->
<form-beans>
<form-bean
name="bean"
type="com.myhome.info.beans.InfoFormBean"/> <!-- name은 아무거나 하고 type는 담을 object 객체를 써준다.(전달된 파라미터 데이터가 설정된 빈 으로 저장이 된다) -->
<!--
DynaActionForm은 예측할 수 없는 파라미터를 참조할때 사용한다.
-->
<form-bean
name="dyna"
type = "org.apache.struts.action.DynaActionForm">
<!--
form bean에 존재하지 않는 파라미터를 참조하기 위해 property를 설정한다.
-->
<form-property name="num" type="java.lang.Integer"/>
<form-property name="name" type="java.lang.String"/>
<form-property name="sex" type="java.lang.String"/>
<form-property name="tel" type="java.lang.String"/>
<form-property name="wdate" type="java.lang.String"/>
</form-bean>
</form-beans>
3. struts-config.xml 에서 <action-mapping> 설정한다.
<!--
[action Attributes]
path = "request 경로"
name = "폼정보를 받아 줄 빈 클래스 이름" - form-bean에 정의 된 이름
scope = "request|session|application" - 다음의 영역으로 들어오는 정보
input = "/info/modify.jsp" - 입력받은 폼 페이지 명 명시
- 정의된 곳에서 들어오는 데이터를 사용하겠다.
forward 부분에서 path만 잡아 주면 주소창은 변하지 않고 페이지만 변경 시킨다.
그래서 redirect를 true를 설정하면 주소 까지 바뀌어 버린다.
-->
<!-- ActionForm을 상속한 bean을 사용할 경우 -->
<action path = "/update"
name = "bean"
scope = "request"
input = "/info/modify.jsp"
type = "com.myhome.info.actions.InfoUpdateAction">
<forward name="success" path="/list.do" redirect="true"/>
</action>
<!-- DynaActionForm 을 사용할 경우 -->
<action path="/delete"
name = "dyna"
scope = "request"
input= "/info.modify.jsp"
type = "com.myhome.info.actions.InfoDeleteAction">
<forward name = "success"
path = "list.do"
redirect="true" />
</action>
<!--
path - 다음과 같은 url패턴으로 들어왔을때
type - 다음에 실행 될 액션을 설정한다.
forward - 다음페이지로 이동되어질 곳을 정한다.
-->
4. Action Class 에서 설정.
//ActionForm을 상속한 경우
public class InfoUpdateAction extends Action{
@Override
public ActionForward execute(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("success");
}
}
//DynaActionForm을 사용한 경우
public class InfoDeleteAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
DynaActionForm dyna = (DynaActionForm)form;
InfoDTO dto = new InfoDTO();
dto.setNum((Integer)dyna.get("num"));
new InfoDAO().delete(dto);
return mapping.findForward("success");
}
}
5. InfoDAO.java, SqlMap.xml에 update, delete 추가.
6. jsp 페이지 수정.
자세한 내용은 war 파일을 참조 한다.
'FrameWork > Struts1' 카테고리의 다른 글
Struts1 FileDownload (0) | 2009.08.18 |
---|---|
Struts1 fileUpload (0) | 2009.08.18 |
Struts1의 Action 4 (0) | 2009.08.16 |
Struts1의 Action 3 (0) | 2009.08.16 |
Struts1의 Action 2 (0) | 2009.08.12 |
Struts1의 Action 1 (0) | 2009.07.27 |
Struts1 에서 iBatis 사용하기 (0) | 2009.07.05 |
Struts 1 을 사용하여 간단한 회원가입, 리스트 불러오기. (0) | 2009.07.05 |
Struts1 개발환경 설정. (0) | 2009.07.05 |
Struts(스트럿츠) 란? (0) | 2009.06.27 |