Web Development Learning Note Structs2 Action Learning Note (iii) Use of action wildcard characters

Source: Internet
Author: User

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.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>
three: Class Package
Structs2 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 Analysis

To 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.

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.