liguofeng29’s blog

個人勉強用ブログだっす。

Struts2 - Convention(協定) - Action Chain

Action処理後にviewではなく、他のActionへ遷移することをActionChainと言う。

Conventionによる、ActionChainする際にルール

  • 遷移元Actionのview名がない
  • 遷移先Actionは遷移元Actionと同じパッケージ内
  • 遷移先ActionのURLは、firstActionName + resultCode

遷移元

package lee.action;
import com.opensymphony.xwork2.ActionSupport;

public class FirstAction extends ActionSupport {
    public String execute() throws Exception {
        System.out.println("first");
        addActionMessage("FirstAction");
        // first-secondのview名がない
        return "second";
    }
}

遷移先

package lee.action;
import com.opensymphony.xwork2.ActionSupport;

public class FirstSecondAction extends ActionSupport {
    public String execute() throws Exception {
        System.out.println("second");
        addActionMessage("SecondAction");

        return "success";
    }
}

first-second-success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!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">
</head>
<body>
    <s:actionmessage/>
</body>
</html>