1. wildcard 1) Disadvantages of the Execute method suppose there is A need: A. There is an action as PersonAction. B. In PersonAction, four methods are required: add, delete, modify, and query. C. But there is only one execute method D in the method entry in the action. To do this, you can add parameters in the url link. The code in the action may be like this: PatternActionpublic class PatternAction extends ActionSupport {private String method; public String execute () {if (method. equals ("add") {// add operation} else if (method. equals ("update") {// modify operation} else if (method. equals ("delete") {// delete operation} else {// query operation} return "" ;}} it can be seen that the write structure is not very good. The emergence of wildcards solves this problem. Pattern. the add method for jsp access to PersonAction: <br> <a href = "$ {pageContext. request. contextPath}/pattern/patternAction. action> test </a> <br> Struts-pattern.xml <package name = "pattern" namespace = "/pattern" extends = "struts-default"> <action name = "patternAction" method = "add" class = "cn. itcast. struts2.action. pattern. patternAction "> </action> </package> PatternActionpublic String add () {return" add ";} 2) method attribute Pattern. jsp access Pe RsonAction add method: <br> <a href = "$ {pageContext. request. contextPath}/pattern/patternAction. action> test </a> <br> Struts-pattern.xml <package name = "pattern" namespace = "/pattern" extends = "struts-default"> <action name = "patternAction" method = "add" class = "cn. itcast. struts2.action. pattern. patternAction "> </action> </package> PatternActionpublic String add () {return" add ";} description: the code above shows that as long as the value of the method attribute in the configuration file is the same as the method name. However, this writing method has drawbacks. Five methods are required in aciton. Five configurations need to be written in the struts configuration file, which leads to a large length of space in the configuration file. It is also highly repetitive. 3) the dynamic call method uses the action name in the url! The method name can be dynamically called. Pattern. jsp dynamically calls the add method in PatternAction: <br> <a href = "$ {pageContext. request. contextPath}/pattern/patternAction! Add. action> test </a> struts-pattern.xml <action name = "patternAction" class = "cn. itcast. struts2.action. pattern. patternAction "> </action> note: In this case, the method attribute is not required in the configuration file. 4) wildcard ing requirements: a_add.action, B _add.action, and c_add.action all request the add method Pattern of PatternAction. jsp wildcard ing instance 1: <br> <a href = "$ {pageContext. request. contextPath}/pattern/a_add.action "> test </a> <a href =" $ {pageContext. request. contextPath}/pattern/B _add.action "> test </a> <a hre F = "$ {pageContext. request. contextPath}/pattern/c_add.action"> test </a>: the paths of a_add, B _add, and c_add point to the add method of PatternAction. Struts-pattern.xml <action name = "a_add" method = "add" class = "cn. itcast. struts2.action. pattern. patternAction "> </action> <action name =" B _add "method =" add "class =" cn. itcast. struts2.action. pattern. patternAction "> </action> <action name =" c_add "method =" add "class =" cn. itcast. struts2.action. pattern. patternAction "> </action> the above structure is poor. The improvements are as follows: <action name =" * _ add "method =" add "class =" cn. itcast. struts2.action. pattern. PatternAction "> (1). Map the add method Pattern of the Request PersonAction and StudentAction. jsp wildcard ing instance 2: <br> <a href = "$ {pageContext. request. contextPath}/pattern/personAction_add.action "> request the add method of personAction </a> <a href =" $ {pageContext. request. contextPath}/pattern/studentAction_add.action "> request the add method of studentAction </a> (2), ing two Struts-pattern.xml <action name = "personAction_add" method = "add" class = "cn. itcast. struts2.action. pattern. per SonAction "> </action> <action name =" studentAction_add "method =" add "class =" cn. itcast. struts2.action. pattern. studentAction "> </action> improvement: <action name =" * _ add "method =" add "class =" cn. itcast. struts2.action. pattern. {1} "/> Note: * Corresponds to {1. Requirement: add, delete, modify, and query methods are available in TeacherAction. How can I write configuration files easily at this time? Pattern. jsp wildcard ing instance 3: <a href = "$ {pageContext. request. contextPath}/pattern/PersonAction_add.action "> request the add method of teacherAction </a> <a href =" $ {pageContext. request. contextPath}/pattern/StudentAction_update.action "> update Method for requesting teacherAction </a> <a href =" $ {pageContext. request. contextPath}/pattern/StudentAction_delete.action "> request the delete method of teacherAction </a> <a href =" $ {pageContext. request. contextPath}/pattern/StudentAc Tion_query.action "> query method for requesting teacherAction </a> struts-pattern.xml <action name =" teacherAction _ * "method =" {1} "class =" cn. itcast. struts2.action. pattern. teacherAction "> </action> Note: * is consistent with the value of method. Extension: <action name = "* _ *" method = "{2}" class = "cn. itcast. struts2.action. pattern. {1} "> </action> the first * matches {1}, the second * matches {2} (3), and the ing is 3. 2. before specifying the request suffix to be processed by Struts 2, we use it by default. the suffix of the action to access the Action. In fact, the default suffix is through the constant "struts. action. extension "to modify, for example: we can configure Struts 2 to only process. do is the request path with the suffix: If you need to specify multiple request suffixes, multiple suffixes are separated by commas. For example: <constant name = "struts. action. extension "value =" do, go "/> 3. A constant can be defined in struts. xml or struts. properties configuration. We recommend that you use struts. xml configuration. The two configuration methods are as follows. configure the constant <struts> <constant name = "struts. action. extension "value =" do "/> </struts> In struts. configure the constant struts in properties. action. extension = do because constants can be defined in the following configuration files, we need to understand the order in which struts2 loads constants: struts-default.xmlstruts-plugin.xmlstruts.xmlstruts.propertiesweb.xml if the same constant is configured in multiple files The constant value configured in the last file overwrites the constant value configured in the previous file. 4. Common constants <! -- Specify the default sequence set, acting on the setCharacterEncoding method of HttpServletRequest and the output of freemarker and velocity --> <constant name = "struts. i18n. encoding" value = "UTF-8"/> <! -- This attribute specifies the request suffix to be processed by Struts 2. The default value of this attribute is action, that is, all requests matching *. action are processed by Struts2. If you need to specify multiple request suffixes, multiple suffixes are separated by commas. --> <Constant name = "struts. action. extension" value = "do"/> <! -- Sets whether the browser caches static content. The default value is true (used in the production environment). It is best to disable it during development --> <constant name = "struts. serve. static. browserCache "value =" false "/> <! -- When the struts configuration file is modified, whether the system automatically reloads the file. The default value is false (used in the production environment). It is best to open the file during development --> <constant name = "struts. configuration. xml. reload "value =" true "/> <! -- Used in development mode to print more detailed error information --> <constant name = "struts. devMode" value = "true"/> <! -- Default view topic --> <constant name = "struts. ui. theme" value = "simple"/> <! -When integrating with spring, specify that spring is responsible for creating action objects --> <constant name = "struts. objectFactory" value = "spring"/> <! -This attribute sets whether Struts 2 supports dynamic method calls. The default value of this attribute is true. To disable dynamic method calling, set this attribute to false. --> <Constant name = "struts. enable. DynamicMethodInvocation" value = "false"/> <! -- Size limit of uploaded files --> <constant name = "struts. multipart. maxSize "value =" 10701096 "/> 5. struts2 processing process l StrutsPrepareAndExecuteFilter is the core controller of the Struts 2 framework. It intercepts all user requests specified by <url-pattern>/* </url-pattern>, when user requests arrive, the Filter filters user requests. By default, if the path of the user request does not contain a suffix or suffix ending with. action, the request will be transferred to the Struts 2 Framework for processing. Otherwise, the Struts 2 Framework will skip the processing of the request. When a request is transferred to the Struts 2 Framework for processing, it passes through a series of interceptors and then to the Action. Unlike Struts1, Struts2 creates an Action for each user request, so the Action in Struts2 is thread-safe. 6. multiple struts configuration files are specified for the application in most applications. As the application scale increases, the number of actions in the system will also increase significantly, resulting in struts. the xml configuration file becomes very bloated. To avoid struts. xml files are too large and bloated to improve struts. for the readability of xml files, we can set a struts. the xml configuration file is divided into multiple configuration files, and then in struts. the xml file contains other configuration files. The following struts. xml specifies multiple configuration files through the <include> element: <struts> <include file = "struts-user.xml"/> <include file = "struts-order.xml"/> </struts> in this way, we can add the Action of Struts 2 to multiple configuration files by module. 7. dynamic method call www.2cto.com. If there are multiple methods in the Action, we can use it! + The method name calls the specified method. Public String execute () throws Exception {this. message = "My first struts2 application"; return "success";} public String other () throws Exception {this. message = "second method"; return "success";} assume that the URL path for accessing the above action is/struts/test/helloworld. action; to access the action's other () method, we can call:/struts/test/helloworld! If you do not want to use dynamic method call for other. action, you can disable dynamic method call by using the constant struts. enable. DynamicMethodInvocation. <Constant name = "struts. enable. DynamicMethodInvocation" value = "false"/>