Confusing about Global forward and Action mapping

Xitrum picture Xitrum · Feb 20, 2012 · Viewed 9.6k times · Source

for example

    <global-forwards>
      <forward name="welcome"  path="/Welcome.do"/>
    </global-forwards>

    <action-mappings>
      <action path="/Welcome" forward="/welcomeStruts.jsp"/>
    </action-mappings>

My question is: When client requests Welcome.do page, the global forward will map the /welcome.do page with the name attribute "welcome". Then in action-mapping it will map between the name in forward tag with the path in action tag so it will know that it should forward to the welcomeStruts.jsp file.
Am I correct?
If not, how can it determine the correct mapping between user's request *.do to the corresponding jsp file?
Thank you

Answer

JB Nizet picture JB Nizet · Feb 20, 2012

You're not correct. When a request comes in, Struts tries to map the URL or the request with the path of an action. Forwards are not used at this stage.

When the action returns a forward name, Struts first looks for a forward with this name in the forwards of the action, and if not found, it looks in the global forwards.