특별한딸기이야기
요청 파라미터 처리(RequestUtil이용) 본문
먼저 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>
<action path="/insertForm" forward="/InsertForm.jsp"/>
<action path="/insert" type="com.tistory.special0strawberry.MemberInserAction"/>
</action-mappings>
</struts-config>
Member class
package com.tistory.special0strawberry;
public class Member
{
private String id;
private String password;
private String name;
private String phone;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
//특별한 것 없는 getter/setter 들어있는 클래스입니다.
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.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);
Member member = new Member();
RequestUtils.populate(member, request);
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());
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>
jsp에서 폼을 통해 사용자로부터 값을 입력받습니다.
'딸기 공부방 > struts and spring' 카테고리의 다른 글
요청 파라미터 처리(DynaActionForm이용) (1) | 2008.11.12 |
---|---|
요청 파라미터 처리(ActionForm이용) (1) | 2008.11.12 |
struts action 종류들이랄까요... (2) | 2008.11.12 |
sturuts 기본 xml이랄까요... (1) | 2008.11.12 |
struts 교재 올라온 카페 글 (0) | 2008.11.05 |