특별한딸기이야기
요청 파라미터 처리(DynaActionForm이용) 본문
strust-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>
<action-mappings>
<action path="/insertForm" forward="/InsertForm.jsp"/>
<action path="/insert" type="com.tistory.special0strawberry.MemberInserAction"
name="memberForm" scope="request" validate="false"/>
</action-mappings>
</struts-config>
MemberInserAction class
//MemberInsertAction으로 만들고 싶었는데... OTL
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"));
return null;
}
}
InsertForm.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 Form
</title>
</head>
<body>
<form action="/Tytolee/insert.do" name="insert">
Id :
<input type="text" name="id"/>
<br/>
Password :
<input type="password" name="password"/>
<br/>
Name :
<input type="text" name="name"/>
<br/>
Phone :
<input type="text" name="phone"/>
<br/>
<input type="submit" value="확인"/>
</form>
</body>
</html>
'딸기 공부방 > struts and spring' 카테고리의 다른 글
View영역으로 포워딩(new 연산자 이용) (0) | 2008.11.12 |
---|---|
요청 파라미터 처리(파일 업로드 처리) (0) | 2008.11.12 |
요청 파라미터 처리(ActionForm이용) (1) | 2008.11.12 |
요청 파라미터 처리(RequestUtil이용) (1) | 2008.11.12 |
struts action 종류들이랄까요... (2) | 2008.11.12 |