Verifying the Find path of an action in struts2

Source: Internet
Author: User

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)  
    1. <s:form action= "/a/b/user" >
    2. <s:textfield label= "username" name= "name"/>
    3. <s:submit></s:submit>
    4. </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:
  1. <struts>
  2. <!--default namespace-
  3. <package name="a" namespace= "" extends= "struts-default">
  4. <action name="user" class="com.easyteam.action.UserAction">
  5. <result >
  6. /success2.jsp
  7. </result>
  8. </Action>
  9. </Package>
  10. <!--namespace is/A--
  11. <package name="B" namespace="/A" extends="Struts-default">
  12. <action name="user" class="com.easyteam.action.UserAction">
  13. <result >
  14. /success1.jsp
  15. </result>
  16. </Action>
  17. </Package>
  18. <!--namespace is/a/b-->
  19. <package name="C" namespace="/a/b" extends="Struts-default">
  20. <action name="user" class="com.easyteam.action.UserAction">
  21. <result >
  22. /success.jsp
  23. </result>
  24. </Action>
  25. </Package>
  26. </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  
  1. <struts>
  2. <!--default namespace -
  3. <package name="a" namespace= "" extends= "struts-default">
  4. <action name="user" class="com.easyteam.action.UserAction">
  5. <result >
  6. /success2.jsp
  7. </result>
  8. </Action>
  9. </Package>
  10. <!--namespace is/A--
  11. <package name="B" namespace="/A" extends="Struts-default">
  12. <action name="user" class="com.easyteam.action.UserAction">
  13. <result >
  14. /success1.jsp
  15. </result>
  16. </Action>
  17. </Package>
  18. <!--namespace is/a/b-->
  19. <!--<package name="C" namespace="/a/b" extends="Struts-default" >
  20. <action name="user" class="com.easyteam.action.UserAction">
  21. <result >
  22. /success.jsp
  23. </result>
  24. </Action>
  25. </Package>
  26. --></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:  
  1. <struts>
  2. <!--default namespace-
  3. <package name="a" namespace= "" extends= "struts-default">
  4. <action name="user" class="com.easyteam.action.UserAction">
  5. <result >
  6. /success2.jsp
  7. </result>
  8. </Action>
  9. </Package>
  10. <!--namespace is/a--><!--
  11. <package name="B" namespace="/A" extends="Struts-default">
  12. <action name="user" class="com.easyteam.action.UserAction">
  13. <result >
  14. /success1.jsp
  15. </result>
  16. </Action>
  17. </Package>
  18. --><!--namespace for/a/b-->
  19. <!--<package name="C" namespace="/a/b" extends="Struts-default" >
  20. <action name="user" class="com.easyteam.action.UserAction">
  21. <result >
  22. /success.jsp
  23. </result>
  24. </Action>
  25. </Package>
  26. --></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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.