특별한딸기이야기

View영역으로 포워딩(new 연산자 이용) 본문

딸기 공부방/struts and spring

View영역으로 포워딩(new 연산자 이용)

특별한녀석 2008. 11. 12. 16:05


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"));
  
  ActionForward forward = new ActionForward();
  
  forward.setPath("/insertResult.do?id=" + member.getString("id"));
  forward.setModule("");
  forward.setRedirect(true);
  
  return forward;
 }
}

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>