Before watching the video of online struts2, which explained to the action of the search path, the instructor said that the action is looked up in order, such as a request for/a/b/ueraction.action, first will go to/a/ B in the namespace to find the action of useraction, if not found in a namespace to find useraction action, if not found, and so on, until the default namespace is found, if not found, the program will throw an exception. But lately I've seen a book that explains this, or is this request/a/b/ueraction.action, first to find the action of useraction in the/a/b namespace, If you can't find it, go to the default namespace and look for the useraction action instead of to the/a namespace. Obviously there is a discrepancy between the two statements. Prove it today with the code. 1. Home Core code (the requested path is/a/b/user)
- <s:form action= "/a/b/user" >
- <s:textfield label= "username" name= "name"/>
- <s:submit></s:submit>
- </s:form>
2. Write three simple jumps after the page success.jsp success1.jsp success2.jsp, the core code is:
-
-
-
The core configuration code for 3.struts.xml is:
- <struts>
- <!--default namespace-
- <package name="a" namespace= "" extends= "struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success2.jsp
- </result>
- </Action>
- </Package>
- <!--namespace is/A--
- <package name="B" namespace="/A" extends="Struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success1.jsp
- </result>
- </Action>
- </Package>
- <!--namespace is/a/b-->
- <package name="C" namespace="/a/b" extends="Struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success.jsp
- </result>
- </Action>
- </Package>
- </struts>
The configuration of these three spaces is ordered in such a way that it is possible to prevent the execution in order.
The result of the operation is: The result shows that the action will be first searched from the specified namespace. (This is the same on the web and in the book, no objection) in changing the struts.xml to this, is the third comment out
- <struts>
- <!--default namespace -
- <package name="a" namespace= "" extends= "struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success2.jsp
- </result>
- </Action>
- </Package>
- <!--namespace is/A--
- <package name="B" namespace="/A" extends="Struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success1.jsp
- </result>
- </Action>
- </Package>
- <!--namespace is/a/b-->
- <!--<package name="C" namespace="/a/b" extends="Struts-default" >
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success.jsp
- </result>
- </Action>
- </Package>
- --></struts>
The result of the operation is: The result shows that the path to/A is searched. In changing the struts.xml to this, the second and the third are commented out:
- <struts>
- <!--default namespace-
- <package name="a" namespace= "" extends= "struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success2.jsp
- </result>
- </Action>
- </Package>
- <!--namespace is/a--><!--
- <package name="B" namespace="/A" extends="Struts-default">
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success1.jsp
- </result>
- </Action>
- </Package>
- --><!--namespace for/a/b-->
- <!--<package name="C" namespace="/a/b" extends="Struts-default" >
- <action name="user" class="com.easyteam.action.UserAction">
- <result >
- /success.jsp
- </result>
- </Action>
- </Package>
- --></struts>
The results of the operation are:
This result indicates that the default namespace is to be searched. In summary: The action of the search is in order to find the top-level (there are many of the above two views, some even to two combinations, but they did not give specific proof code, just give a logical description, I here the test may not be rigorous, I implore you to criticize, together with progress)
Verifying the Find path of an action in struts2