Struts1 中的 global-forward

全局forward ,struts先从局部找name,若没有再从全局找name:


     <global-forwards>
         <forward name="login" path="/login.jsp" />
     </global-forwards>

 对应到Struts2中的global-result

在struts-config.xml的文件中我们配置了许多的action,每一个action中都可以有多个forward,当页面发送请求后,RequestProcessor会根据请求的URI到struts-config.xml中寻找相应的Action对象,Action对象会根据不同的条件得到不同的ActionForward对象,ActionServlet根据不同的ActionForward指向不同的页面。

 

如果在多个action中都有相同的forward指向相同的页面,那么这些相同的forward就可以统一的配置到global-forwards中,而不需要重复的出现在各个action中,减少配置文件的复杂性。例如:

 

<struts-config>  
  1.         <!--这些forward是多个action都有的,放到这里统一管理-->  
  2.     <global-forwards>  
  3.         <forward name="exit" path="/index.jsp"/>  
  4.     </global-forwards>  
  5.     <action-mappings>  
  6.         <action path="/hello" type="com.king.action.HelloAction">  
  7.             <forward name="helloUser" path="/WEB-INF/pages/hello.jsp"/>  
  8.         </action>  
  9.     </action-mappings>  
  10. </struts-config>  
posted @ 2014-03-15 16:36  Esteban.  阅读(481)  评论(0编辑  收藏  举报