<global-results>
<result name="mainpage">
/mainpage.jsp
</result>
</global-results>
定义了一个公用的结果集,表示如果其他包若要使用该结果集,只要使用extends。
如下:
<?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>
<!-- <constant name="struts.enable.DynamicMethodInvocation" value="true" /> -->
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="GBK" />
<package name="user" namespace="/user" extends="struts-default">
<global-results>
<result name="mainpage">
/mainpage.jsp
</result>
</global-results>
<action name="user" class="com.test.UserAction">
<result>
/student_success.jsp
</result>
<result name="error">
/student_error.jsp
</result>
</action>
</package>
<package name="admin" namespace="/admin" extends="user"> <!-- 表示使用上面的user包中的global-results -->
<action name="admin" class="com.test.AdminAction">
<result>
/admin.jsp
</result>
</action>
</package>
</struts>
AdminAction类如下:
package com.test;
import com.opensymphony.xwork2.ActionSupport;
public class AdminAction extends ActionSupport{
public String execute()throws Exception{
return "mainpage";
}
}