Methods of using wildcards in struts 2 configuration files (three forms)
Introduction to struts 2
Struts 2 is a web application framework based on MVC design pattern. It is essentially equivalent to a servlet. In MVC design pattern, struts 2 acts as a controller to establish the data interaction between model and view. Struts 2 is the next generation product of struts. It is a new struts 2 framework based on the technology of struts 1 and webwork. The architecture of its new struts 2 is very different from that of struts 1. Struts 2 takes webwork as the core and uses the interceptor mechanism to process user requests. This design also enables the business logic controller to be completely separated from the servlet API. Therefore, struts 2 can be understood as an updated product of webwork. Although there are too many changes from struts 1 to struts 2, the change of struts 2 is very small compared with webwork.
Form 1: call different methods in the same action
<action name="*Action" class="Jcuckoo.LoginRegistAction" method="{1}"> <result name="input">/login.jsp</result> <result name="error">/error.jsp</result> <result name="success">/welcome.jsp</result> </action>
Where the value of expression {1} is the value of the first * in the name attribute value.
If the URL requested by the user is loginaction Action, call jcuckoo Login method in loginregistaction;
If the URL requested by the user is registeraction Action, call jcuckoo Register method in loginregistaction;
Form 2: call the execute method of different actions through matching
<action name="*Action" class="Jcuckoo.{1}Action"> <result name="input">/login.jsp</result> <result name="error">/error.jsp</result> <result name="success">/welcome.jsp</result> </action>
The method attribute does not appear above, so the corresponding execute method is called by default
If the URL requested by the user is loginaction Action, call jcuckoo Execute method in loginaction;
If the URL requested by the user is registeraction Action, call jcuckoo Execute method in registeraction;
Form 3: dynamic results
<action name="crud_*" class="Jcuckoo.CrudAction" method="{1}"> <result name="input">/input.jsp</result> <result>/{1}.jsp</result> </action>
When the processing result is input, go to / input JSP page
When the processing result is success,
summary
The above is the method of using wildcards in the struts 2 configuration file introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support to our website! If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!