1. * wildcard Code Optimization struts.xml
Creating a class action of UserAction
Package Action; Import com.opensymphony.xwork2.ActionSupport; public class the UserAction the extends ActionSupport { // add the user public String the Add () { return SUCCESS; } // delete user public String Delete () { return SUCCESS; } // update user public String Update () { return SUCCESS; } // find the user public String Find () { return SUCCESS; } }
Struts.xml file configuration
<!--第一种配置方式--> <!--<package name="p2" extends="struts-default"> <action name="add" class="action.UserAction" method="add"> <result name="success">/add.jsp</result> </action> <action name="delete" class="action.UserAction" method="delete"> <result name="success">/delete.jsp</result> </action> <action name="find" class="action.UserAction" method="find"> <result name="success">/find.jsp</result> </action> <action name="update" class="action.UserAction" method="update"> <result name="success">/update.jsp</result> </action> </ Package>-> <! - use wildcards way -> <! - the operation of the access wildcard *: This is a * -> < Package name = "P2" the extends = "Struts-default" > < Action name = "*" class = "action.UserAction" Method = "{}. 1" > < Result name = "Success" > /{1}.jsp </ Result > </ Action > </ Package >