「Struts2開発」Global_Resultsの使い方
1.UserAction
package com.startnews.struts2.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
private static final long serialVersionUID = 1L;
public Integer type;
public String execute(){
System.out.println(“type = " + this.type);
if(type == 1) return SUCCESS;
if(type == 0) return ERROR;
else return “mainpage";
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}
2.struts.xml
<?xml version="1.0″ encoding="UTF-8″ ?>
<!DOCTYPE struts PUBLIC
“-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
“http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.configuration.xml.reload" value="true"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="default"></default-action-ref>
<global-results>
<result name="top">/top.jsp</result>
</global-results>
<action name="default">
<result>/default.jsp</result>
</action>
</package>
<package name="type" namespace="/type" extends="default">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="user" class="com.startnews.struts2.user.action.UserAction">
<result>/user_success.jsp</result>
<result name="error">/user_error.jsp</result>
</action>
</package>
<package name="admin" namespace="/admin" extends="default">
<action name="admin" class="com.startnews.struts2.user.action.AdminAction">
<result>/admin.jsp</result>
</action>
</package>
</struts>