[Web Development Study Notes] Structs2 Action Study Notes (3) use of the action wildcard

Source: Internet
Author: User

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.

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.