The Struts framework learns several ways to develop action
Mode 1: Inherit Actionsupport If you use the Struts checksum feature, you must inherit this class
Method 2: Implement the Action interface
Mode 3: Do not inherit any classes, do not implement any interfaces
1. Wildcard characters:
Configuration information in struts, can be optimized with * and {1}
Public classuseraction {PrivateString UserName; Public voidsetusername (String userName) { This. UserName =UserName; } //Business processing methods in action PublicString Login () {System.out.println ("Useraction.login ()" +userName); return"Login"; } PublicString Register () {System.out.println ("Register ()" +userName); return"Register"; }}
< Packagename= "config"namespace= "/user"extends= "Struts-default"Abstract= "false"> <!--<action name= "Login" class= "cn.itcast.a_config. Useraction "method=" Login "> <result name=" Success ">/index.jsp</result> </a ction> <action name= "register" class= "Cn.itcast.a_config. Useraction "method=" register "> <result name=" Success ">/index.jsp</result> < ;/action> - <!--use wildcard characters to optimize the above steps - <!--Http://localhost:8080/struts02/user_login - <Actionname= "User_*"class= "Cn.itcast.a_config." Useraction "Method= "{1}"> <resultname= "{1}">/{1}.jsp</result> </Action> </ Package>
2. Path matching principle
3. Constants
In the Struts-default.xml file:
<!--- <name = "Struts.action.extension" value= "Action,do,"></constant>
<Struts> <!--first, the global configuration - <!--0. Request Data Encoding - <constantname= "Struts.i18n.encoding"value= "UTF-8"/> <!--1. Modify the Struts default access suffix - <constantname= "Struts.action.extension"value= "Action,do,"></constant> <!--2. Modify XML Auto Reload - <constantname= "Struts.configuration.xml.reload"value= "true"/> <!--3. Turn on dynamic method invocation (default does not open) - <constantname= "Struts.enable.DynamicMethodInvocation"value= "true"/> <!--4. Change the maximum size of the uploaded file to 30M - <constantname= "Struts.multipart.maxSize"value= "31457280"/></Struts>
<Struts> < Packagename= "Config2"namespace="/"extends= "Struts-default"> <!--Dynamic method invocation: Http://locahost:8080/struts02/user!login <action name= "user" class= "cn.itcast.b_config2. Useraction "> <result name=" Success ">/index.jsp</result> </action> - <!--wildcard character: Http://locahost:8080/struts02/user_login - <Actionname= "User_*"class= "Cn.itcast.b_config2." Useraction "Method= "{1}"> </Action> <!--<action name= "test" class= "Cn.itcast.b_config2. Testaction "Method=" execute > Return result tag success The corresponding page is not configured in the current action, so we will find out if there is a success tag corresponding to the global configuration. </action> - <!--what happens when class is not configured? The Aciton that is processed - <!--answer: When just need to jump to web-inf resources. - <Actionname= "Test2"> <resultname= "Success">/web-inf/index.jsp</result> </Action> </ Package> </Struts>
Global-results Global Jump View must be written before action
<!--- <!--name is only configured with access path names class The action that is executed by default is configured in Struts-default <default-class-ref class= "Com.opensymphony.xwork2.ActionSupport"/> method defaults to execute by default, execute returns a value of success, and the corresponding page goes to the global view. -
<name= "Test"></action>
Struts wildcard path matching constant usage Configure default values