Action Learning Note 3-discussion of wildcard characters
Use wildcards to minimize the amount of configuration, but be sure to follow the "Convention better than the configuration" principle.
One: Front-end htm
< front-end code html>
Two: Struct.xmlstruct.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>
three: Class PackageStructs2 called Class Pack package Com.struts2.action;import Com.opensymphony.xwork2.actionsupport;public class Studentaction Extends Actionsupport {public String Add () {return SUCCESS;} Public String Delete () {return SUCCESS;}}
Four: Process AnalysisTo perform the steps: Click <a href= "<%=context%>/actions/studentadd" > Add students </a> find Struct.xml via/actions/ Studentadd-no match action, then the call class class= "Com.struts2.action.StudentAction" with student* inside namespace- > Execution method Selection,Studentadd after matching with student*, * is represented as add,{1},{2} after the selection is discussed.
v.: DiscussionAdd 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;}}
when we click <a href= "<%=context%>/actions/teacheradd > Add teacher </a> struct.xml find/actions/teacheradd-no match action, then *_ in namespace * Matching call class class= "com.struts2.action.{ 1}action, the selection of the execution method, teacher matches the first asterisk in *_*, the second * is represented as add,{1},{2} and the selection is determined according to the order of the *.
VI: ConclusionIf the agreement is good, the configuration is extremely simple. With the fifth step discussion, the configuration does not need to be modified after we continue to add the new class.