Use of wildcard characters

Source: Internet
Author: User

1. Create a new class Actionwildcard, and verify the wildcard method, such as:

2. Add student two methods that need to be practiced add,deete

 Package Cn.cqvie.wildcard; Import Com.opensymphony.xwork2.ActionSupport;  Public class extends actionsupport { public String Add () {return  SUCCESS;}  Public String Delete () {return  SUCCESS;}}

3. Add teacher two methods that need to be practiced add,deete

 Package Cn.cqvie.wildcard; Import Com.opensymphony.xwork2.ActionSupport;  Public class extends actionsupport { public String Add () {return  SUCCESS;}  Public String Delete () {return  SUCCESS;}}

This allows you to create a new two JSP page to display the results of the run

4. New studentadd_success.jsp: Note that the student here must be capitalized, just write a word in the body

<body>Student Add Success! <br></body>

5. New studentdelete_success.jsp: Note that the student here must be capitalized, just write a word in the body

<body>student Delete success!<br></body>

6. New teacher_add_success.jsp: Note that the T must be capitalized, just write a word in the body

<body>Teacher Add SUCCESS!<br></body>

7. New teacher_delete_success.jsp: Note that the T must be capitalized, just write a word in the body

<body>Teacher Delete Success! <br></body>

8. Configure the contents of the Struts.xml file: * * *

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.1//en" "http://struts.apache.org/dtds/ Struts-2.1.dtd "><struts><constant name=" Struts.devmode "value=" true "/> < Package Extendsclassclass= "Cn.cqvie.wildcard. {1} Action "method=" {2} "><result >/{1}_{2}_success.jsp</result></action></ Package ></struts>

9. "*" Here represents all, that is, all methods that student has, {1}= "*", that is, "{1}" means "add" when "*" stands for "add". This means that "*" is consistent with the "{}" content.

"*_*" stands for: the first "*" stands for "Teacher"; the second "*" represents the "add" method or the "delete" method.

10. Modify the mapping in Web. xml: You need to change the Url-pattern original "*.action" to "/*", otherwise you cannot find the method corresponding to the actions.

<filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</ Url-pattern></filter-mapping></web-app>

11. Run/debug, deploy the project on Tomcat, open the browser in the Address bar to enter the name of the item, enter, separate points "add student", "delete student", "Add Teacher", "delete teacher" can successfully jump to the page

12 Summary: Pay attention to the case of letters, when configuring the "Struts.xml" file, the corresponding "action" action to be consistent with, follow the "Convention better than the configuration" principle

Use of wildcard characters

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.