Action Study Notes 3-about wildcards
Use wildcards to minimize the number of configurations. However, you must abide by the principle that "conventions are better than configurations.
I. Front-end htm
<Front-end code html> Ii. struct. xml
//struct.xml<struts> <constant name="struts.devMode" value="true" /> <package name="actions" extends="struts-default" namespace="/actions"> <action name="Student*" class="com.struts2.action.StudentAction" method="{1}"> <result>/Student{1}_success.jsp</result> </action> <action name="*_*" class="com.struts2.action.{1}Action" method="{2}"> <result>/{1}_{2}_success.jsp</result> </action> </package></struts>
Iii. Class packages
// The class package com. Called by structs2. struts2.action; import com. opensymphony. xwork2.ActionSupport; public class StudentAction extends ActionSupport {public String add () {return SUCCESS;} public String delete () {return SUCCESS ;}}
Iv. Process Analysis
Procedure: Click <a href = "<% = context %>/actions/Studentadd"> Add student </a>-> use struct. xml lookup/actions/Studentadd-> there is no action that matches with Student * In namespace-> call class = "com. struts2.action. studentAction-> select the execution method. After Studentadd matches Student *, * indicates the selection of add, {1}, {2.
5. Add a new class
package com.bjsxt.struts2.action;import com.opensymphony.xwork2.ActionSupport;public class TeacherAction extends ActionSupport {public String add() {return SUCCESS;}public String delete() {return SUCCESS;}}
Click <a href = "<% = context %>/actions/TeacherAdd"> Add instructor </a>-> through struct. xml lookup/actions/TeacherAdd-> there is no action that matches with the * _ * in the namespace-> call class = "com. struts2.action. {1} Action-> execution method selection. After Teacher matches the first Asterisk In * _ *, the second Asterisk is represented as add, {1 }, the selection of {2} is determined.
6. If the conclusion is agreed, the configuration is extremely simple. As discussed in step 5, the configuration does not need to be modified after we continue to add new classes.