为什么这段代码不会进入无限循环?

why does this code doesn't go into infinite loop?

1)

我正在查看一些可能是 Struts1 的代码,想知道是否有人可以解释为什么我没有得到无限循环,相反,我被转发到 jsp 页面改为:

struts-config.xml:

<struts-config>
     <global-forwards>
        <forward name="a.t" path="/Search.do"/>
     </global-forwards>
     <action-mappings>
        <action path="/Search"
              type="path.SearchAction"
              scope="request"
              name="searchForm"
              validate="true">
        <forward name="orders" path="a.t"/>
        <forward name="success" path="a.t"/>
        <forward name="cancel" path="/Search.do"/>
        </action>
     </action-mappings>
    ...
 </struts-config>

我搜索了a.t,发现这里也引用了它 tiles.xml。不知道这样做的目的是什么

<tiles-definitions>
   <definition name="a.t"  extends="admin.default">
     <put-attribute name="content" value="/mypath/hello.jsp"/>
   </definition>
</tiles-definitions>

删节 SearchAction.java class:

public class SearchAction extends Action
(
   ....
   public ActionForward execute(ActionMapping mapping, ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response) throws
   Exception 
   {
       ....
       return mapping.findForward("success");
   }
)

我原来的想法是,既然总是returns"success",而根据struts-config.xml

<forward name="success" path="a.t"/>

会去找a.t,定义在global-foward

<struts-config>
        <global-forwards>
           <forward name="a.t" path="/Search.do"/>
        </global-forwards>

和 路径="/Search.do"

理论上会把我送回SearchAction.java

 <action-mappings>
       <action path="/Search"

指向SearchAction.java

2)

不知道原作者为什么决定这样做:

    <forward name="orders" path="a.t"/>
    <forward name="success" path="a.t"/>
    <forward name="cancel" path="/Search.do"/>

有区别吗
  <forward name="success" path="a.t"/>
vs.
  <forward name="success" path="/Search.do"/>

I'm being forwarded to a jsp page instead:

我希望你被转发到 hello.jsp

My Original thinking is that since it always returns "success", and according to the struts-config.xml

<forward name="success" path="a.t"/>

it would go to find a.t, which is defined in the global-foward

<struts-config> <global-forwards> <forward name="a.t" path="/Search.do"/> </global-forwards>

and path="/Search.do"

path="a.t" 将不再在 <global-forwards> 中搜索具有相同名称的映射。相反,它在 tiles.xml 中搜索合适的映射并找到以下块并重定向到 hello.jsp

<tiles-definitions>
   <definition name="a.t"  extends="admin.default">
     <put-attribute name="content" value="/mypath/hello.jsp"/>
   </definition>
</tiles-definitions>

Is there a difference between

 <forward name="success" path="a.t"/>
vs.
  <forward name="success" path="/Search.do"/>

<forward name="success" path="a.t"/> 将映射到 tiles.xml 并转发到 hello.jsp

<forward name="success" path="/Search.do"/> 将映射到 SearchAction.java。由于你只返回了 success,它会再次转到 hello.jsp,但是原作者已经这样做了,因为将来他还可以添加任何其他映射,对于不同的情况,比如 failure

动作class:

return mapping.findForward("failure");

struts-config.xml:

<forward name="failure" path="failure.jsp"/>