Struts1 action inherits different parent classes that have different effects

Source: Internet
Author: User

1.ForwardAction: for request forwarding.

For example: anchor points, in order to maintain the structure of MVC, in the use of Anchor point tag is not directly jump page, but by jumping to xx.do by Forwardaction implementation page jump. Configuration: <action-mappings> <action path= "/tologin" type= "org.apache.struts.actions.ForwardAction " forward= "/login.jsp" > </action> </action-mappings> The Forward property value is the page to jump.   2.incluedeAction: Used to include pages. Jsp: <jsp:include page= "includewelcome.do" ></jsp:include> Configuration: <action-mappings> <action path= "/includewelcome" type= "org.apache.struts.actions.IncludeAction" parameter= "/welcome.jsp" > </action> </action-mappings>   3.DispatchAction: Used to implement a set of related business in a class (multiple submit buttons for one form on the same page). Usage: Write a class to inherit dispatchaction, but remember that you cannot override the Dispatchaction Execute () method. The return value type of the business method, the type of parameter passed and the number of arguments consistent with the execute () method. defect: To use the JS code, if JS is disabled, you can not achieve the relevant business. JSP page: <form action= "train.do" method= "POST" > <input type= "hidden" name= "Training" > <input type= "Submit" value= "feed" name= "eatbtn" onclick= "training.value=" Eat " /> <input type= "Submit" value= "storytelling" name= "talkbtn" onclick= "training.value=" Talk "/> <input type= "Submit" value= "Game" name= "playbtn" onclick= "training.value=" Play ' " /> </form> After clicking the button, the value of the hidden form submission must be consistent with the method name of the business method in Dispatchaction. Configuration: <action path= "/train" type= "com.lovo.struts.action.PetDispatchAction " parameter= "Training" > <forward name= "Petinfo" path= "/petinfo.jsp" ></forward> </action>   4.MappingDispatchAction: For multiple forms one action processing (separate pages, processing a business). Usage: Write a class to inherit mappingdispatchaction, but remember that you cannot override the Mappingdispatchaction Execute () method. The return value type of the business method, the type of parameter passed and the number of arguments consistent with the execute () method. JSP: <form method= "POST" action= "add.do" name= "AddForm" > <input type= "Submit" value= "Add" name= "addbtn" > </form>   <form method= "POST" action= "del.do" name= "Delform" > <input type= "Submit" value= "del" name= "DELBTN" > </form> Configuration: <action path= "/add" type= "com.lovo.struts.action.MyMappingDispatchAction " parameter= "Addstu" > </action>   <action path= "/del" type= "com.lovo.struts.action.MyMappingDispatchAction " parameter= "Delstu" > </action> the property value of the parameter property must be consistent with the method name of the business method in Mappingdispatchaction.   5. lookupdispatchaction: used to implement a set of related business in a class (multiple submit buttons for a form on the same page).    Usage: Write a class to inherit mappingdispatchaction, but remember not to rewrite lookupdispatchaction the Execute () method. The return value type of the business method, the type of parameter passed and the number of arguments consistent with the execute () method. Rewrite Getkeymethodmap () method. You must configure a Form-bean.         JSP page: <input type= "hidden" value= <%= ID%> name= "petid" > when using lookupdispatchaction, the JSP page uses the Struts HTML tag library and the Bean Tag library. As well as the Propperties configuration file. html tag the value of the property must be the same. The value of the key for the HTML tag corresponds the value in the propperties.   Configuration: <form-bean name= "lookup" type= "Org.apache.struts.action.DynaActionForm" ></form-bean>   <action path= "/train" type= "com.lovo.struts.action.PetLookupDispatchAction" name= "Lookup" parameter= " Playbtn "> <forward name= "Petinfo" path= "/petinfo.jsp" > </forward> </action>   the value of the parameter property must be the same as of HTML tags the value of the property is consistent.   6.SwitchAction: Used for page jumps between multiple profiles. Configuration in xml: <init-param> <param-name>config/t87</param-name> <param-value>/WEB-INF/struts-moduleA.xml</param-value> </init-param>   configuration in Struts-config.xml: <action path= "/tot87" type= "org.apache.struts.actions.SwitchAction" >

Struts1 action inherits different parent classes that have different effects

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.