특별한딸기이야기
View 영역으로 포워딩(Global 포워딩) 본문
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>
<form-beans>
<form-bean name="memberForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="id" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
<form-property name="name" type="java.lang.String"/>
<form-property name="phone" type="java.lang.String"/>
</form-bean>
</form-beans>
<global-forwards>
<forward name="success" path="/insertResult.do" module="" redirect="true"/>
</global-forwards>
<action-mappings>
<action path="/insertForm" forward="/InsertForm.jsp"/>
<action path="/insertResult" forward="/InsertResult.jsp"/>
<action path="/insert" type="com.tistory.special0strawberry.MemberInserAction"
name="memberForm" scope="request" validate="false">
<forward name="fail" path="/index.jsp"/>
</action>
</action-mappings>
</struts-config>
<!--
설정파일과 차이점은 Global로 넘어갔느냐의 차이임. 밑의 두개의 파일은 설정 파일과 같은 것임
-->
MemberInserAction class
package com.tistory.special0strawberry;
import javax.servlet.http.HttpServletRequest;
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.DynaActionForm;
import org.apache.struts.util.RequestUtils;
import com.tistory.special0strawberry.Member;
public class MemberInserAction 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);
/*
//RequestUtil use
Member member = new Member();
RequestUtils.populate(member, request);
*/
/*
//ActionForm use
MemberForm member = (MemberForm)form;
System.out.println("member.id : " + member.getId());
System.out.println("member.password : " + member.getPassword());
System.out.println("member.name : " + member.getName());
System.out.println("member.phone : " + member.getPhone());
*/
//DynaActionForm use
DynaActionForm member = (DynaActionForm)form;
System.out.println("member.id : " + member.getString("id"));
System.out.println("member.password : " + member.getString("password"));
System.out.println("member.name : " + member.getString("name"));
System.out.println("member.phone : " + member.getString("phone"));
/*
// new ActionForward use
ActionForward forward = new ActionForward();
forward.setPath("/insertResult.do?id=" + member.getString("id"));
forward.setModule("");
forward.setRedirect(true);
return forward;*/
//return mapping.findForward("success");
return mapping.findForward("fail");
}
}
InsertResult.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>
Insert title here
</title>
</head>
<body>
<%
String id = request.getParameter("id");
if(id == null)
{
id = "noid";
}
out.println(id);
%>
</body>
</html>
'딸기 공부방 > struts and spring' 카테고리의 다른 글
예외처리(프로그램적인 방법) (0) | 2008.11.13 |
---|---|
struts 에러처리에 유용한 plug-in (0) | 2008.11.12 |
View 영역으로 포워딩(설정 파일 정의) (0) | 2008.11.12 |
View영역으로 포워딩(new 연산자 이용) (0) | 2008.11.12 |
요청 파라미터 처리(파일 업로드 처리) (0) | 2008.11.12 |