dispatcher방식으로 action을 호출함



LoginAction (Chain 연습)

package com.ch5.action;

import com.opensymphony.xwork2.Action;

public class LoginAction implements Action{
    
    private String userId;
    private String message;
    
    @Override
    public String execute() throws Exception {
        message = (message==null ? "" : message) + userId + "로 로그인 했습니다.";
        return SUCCESS;
    }  

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}



                       RegisterUser (Chain 연습)

package com.ch5.action;

import com.opensymphony.xwork2.Action;

public class RegisterUser implements Action{

    private String userId;
    private String password;
    private String message;
         
    @Override
    public String execute() throws Exception {
        message = userId + "를 등록했습니다.";
        return SUCCESS;
    }
  
    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getMessage() {
        return message;
    }

    public void setPassword(String password) {
        this.password = password;
    }    
}


struts-ch5.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="ch5" namespace="/ch5" extends="struts-default">
         
<!-- chain -->
        <action name="registerAndLogin" class="com.ch5.action.RegisterUser">
            <interceptor-ref name="params"/>
            <result name="success" type="chain">
                <param name="actionName">login</param>
                <param name="namespace">/ch5</param>
            </result>
        </action>
        <action name="login" class="com.ch5.action.LoginAction">
            <interceptor-ref name="chain"/>
            <interceptor-ref name="params"/>
            <result name="success" type="dispatcher">result.jsp</result>
        </action>

    </package>
</struts>


registerForm.jsp (Chain 연습)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>chain 연습</title>
</head>
<body>
<form action="registerAndLogin.action" method="post">
id:<input type="text" name="userId"><br/>
비밀번호:<input type="password" name="password"><br/>
<input type="submit" value="로그인">
</form>
</body>
</html>



result.jsp (Chain 연습)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>chain 연습</title>
</head>
<body>
${message}
</body>
</html>



                 userForm3.jsp (Chain 연습)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>도메인 오브젝트 테스트</title>
</head>
<body>
<form action="createUser3.action" method="post">
    이름: <input type="text" name="name"><br/>
    나이: <input type="text" name="age"><br/>
    이메일: <input type="text" name="email"><br/>
    <input type="submit" value="전송">
</form>
</body>
</html>






Chapter04.zip



+ Recent posts