<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="demo" extends="struts-default" >
<action name="submit" class="action.MoreSubmitAction">
<result name="save" >
/result.jsp
</result>
<result name="print">
/result.jsp
</result>
</action>
</package>
</struts>
则struts.xml引用newstruts.xml文件的代码如下:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="newstruts.xml"/>
<package name="test" extends="struts-default">

</package>
</struts>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="demo" extends="struts-default" >
<action name="test" class="action.MyAction">

</action>
<action name="my" class="action. MyAction" method="my">

</action>
</package>
</struts>
import com.opensymphony.xwork2.ActionSupport;
public class MyAction extends ActionSupport
{

public String execute() throws Exception
{
// 处理test动作的代码
}
public String my() throws Exception
{
// 处理my动作的代码
}

}
<param name="param1">value1</param>
<param name="param2">value2</param>
<result name="save" >
/result.jsp
</result>

</action>
当然,在action中读这些参数也非常简单,只需要象获取请求参数一样在action类中定义相应的setter方法即可(一般不用定义getter方法)。如下面的代码将读取param1和param2参数的值:
import com.opensymphony.xwork2.ActionSupport;
public class MyAction extends ActionSupport
{
private String param1;
private String param2;
public String execute() throws Exception
{
System.out.println(param1 + param2);
}
public void setParam1(String param1)
{
this.param1 = param1;
}
public void setParam2(String param2)
{
this.param2 = param2;
}

}
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
<!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->
<result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
<package name="demo" extends="struts-default">
<global-results>
<result name="print">/result.jsp</result>
</global-results>
<action name="submit" class="action.MoreSubmitAction">

</action>
<action name="my" class="action.MoreSubmitAction" method="my">

</action>
</package>
</struts>
如果<action>中没有相应的<result>,Struts2就会使用全局的<result>。
















