특별한딸기이야기
struts action 종류들이랄까요... 본문
<!-- struts-config.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<!-- 단순 액션-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<!-- 단순 액션-->
<action path="/soloaction" type="com.tistory.special0strawberry.SoloAction"/>
<!-- 여러 요청 처리 액션 -->
<action path="/multiaction" type="com.tistory.special0strawberry.MultiAction" parameter="method"/>
<!-- 포워딩 액션 -->
<action path="/goindex" forward="/index.jsp"/>
</action-mappings>
</struts-config>
단순 액션 소스
package com.tistory.special0strawberry;
<!-- 여러 요청 처리 액션 -->
<action path="/multiaction" type="com.tistory.special0strawberry.MultiAction" parameter="method"/>
<!-- 포워딩 액션 -->
<action path="/goindex" forward="/index.jsp"/>
</action-mappings>
</struts-config>
단순 액션 소스
package com.tistory.special0strawberry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class SoloAction extends Action
{
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
//return super.execute(mapping, form, request, response);
System.out.println("SoloAction start!");
return null;
}
}
여러 요청 수행하는 멀티액션
package com.tistory.special0strawberry;
{
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
//return super.execute(mapping, form, request, response);
System.out.println("SoloAction start!");
return null;
}
}
여러 요청 수행하는 멀티액션
package com.tistory.special0strawberry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
public class MultiAction extends DispatchAction
{
public ActionForward One(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
//return super.execute(mapping, form, request, response);
System.out.println("One Start!");
return null;
}
public ActionForward Two(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
//return super.execute(mapping, form, request, response);
System.out.println("Two Start!");
return null;
}
}
포워드 액션은 xml에서 지정하면 끝이고...
여러개의 요청을 처리하는 액션은 xml에서 parameter로 지정된 부분을 뒤에 붙여 주어 어떤 메소드를 호출할 지를 결정해 주어야 한다.
ex) http://localhost:8080/Tytolee/multiaction.do?method=Two
{
public ActionForward One(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
//return super.execute(mapping, form, request, response);
System.out.println("One Start!");
return null;
}
public ActionForward Two(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
//return super.execute(mapping, form, request, response);
System.out.println("Two Start!");
return null;
}
}
포워드 액션은 xml에서 지정하면 끝이고...
여러개의 요청을 처리하는 액션은 xml에서 parameter로 지정된 부분을 뒤에 붙여 주어 어떤 메소드를 호출할 지를 결정해 주어야 한다.
ex) http://localhost:8080/Tytolee/multiaction.do?method=Two
'딸기 공부방 > struts and spring' 카테고리의 다른 글
요청 파라미터 처리(DynaActionForm이용) (1) | 2008.11.12 |
---|---|
요청 파라미터 처리(ActionForm이용) (1) | 2008.11.12 |
요청 파라미터 처리(RequestUtil이용) (1) | 2008.11.12 |
sturuts 기본 xml이랄까요... (1) | 2008.11.12 |
struts 교재 올라온 카페 글 (0) | 2008.11.05 |