在struts-config.xml的文件中我们配置了许多的action,每一个action中都可以有多个forward,当页面发送请求后,RequestProcessor会根据请求的URI到struts-config.xml中寻找相应的Action对象,Action对象会根据不同的条件得到不同的ActionForward对象,ActionServlet根据不同的ActionForward指向不同的页面。
如果在多个action中都有相同的forward指向相同的页面,那么这些相同的forward就可以统一的配置到global-forwards中,而不需要重复的出现在各个action中,减少配置文件的复杂性。例如:
- <struts-config>
- <!--这些forward是多个action都有的,放到这里统一管理-->
- <global-forwards>
- <forward name="exit" path="/index.jsp"/>
- </global-forwards>
- <action-mappings>
- <action path="/hello" type="com.king.action.HelloAction">
- <forward name="helloUser" path="/WEB-INF/pages/hello.jsp"/>
- </action>
- </action-mappings>
- </struts-config>