In-depth analysis of dispatchaction, lookupdispatchaction, and mappingdispatchaction First, let's take a look at the relationship between the three of them. Java. Lang. Object | + -- Org. Apache. Struts. action. Action | + -- Org. Apache. Struts. Actions. dispatchaction | + -- Org. Apache. Struts. Actions. lookupdispatchaction | + -- Org. Apache. Struts. Actions. mappingdispatchaction DispatchactionDefinition Public abstract class dispatchaction extends actionThis is an abstract action. It will execute corresponding methods according to the parameter in the request. Different actions can be grouped into an action file through this action class. Struts-config.xml: <Action Path = "/savesubject" type = "org. apache. struts. actions. dispatchaction "name =" subscriptionform "Scope =" request "input ="/subscribe. JSP "parameter =" method "/> There must be a corresponding method in action: Public class demoaction extends dispatchaction { Public actionforward Delete (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception Public actionforward insert (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception Public actionforward Update (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception } You can access your program in this way: Http: // localhost: 8080/MyApp/savesub.pdf. do? Method = Update If the parameter in the parameter is null, the unspecified method in the action is executed. Lookupdispatchactionpublic abstract class lookupdispatchaction extends dispatchactionThe action abstract class inherits the dispatchaction. The execution of the corresponding method is determined by the parameter attribute in actionmapping. It is suitable for a form with many buttons, and different operations are performed by pressing different buttons. Struts-config.xml: <Action Path = "/test" Type = "org. example. myaction" Name = "myform" Scope = "request" Input = "/test. jsp" Parameter = "method"/> Applicationresources. properties: Button. Add = add Button. Delete = Delete JSP: <HTML: Form Action = "/test"> <HTML: Submit property = "method"> <Bean: Message key = "button. Add"/> </Html: Submit> <HTML: Submit property = "method"> <Bean: Message key = "button. Delete"/> </Html: Submit> </Html: Form> Getkeymethodmap must be implemented in action: Protected map getkeymethodmap (){ Map map = new hashmap (); Map. Put ("button. Add", "add "); Map. Put ("button. Delete", "delete "); Return map; } Public actionforward add (actionmapping mapping, Actionform form, Httpservletrequest request, Httpservletresponse response) Throws ioexception, servletexception { // Do add Return Mapping. findforward ("success "); } Public actionforward Delete (actionmapping mapping, Actionform form, Httpservletrequest request, Httpservletresponse response) Throws ioexception, servletexception { // Do Delete Return Mapping. findforward ("success "); } Mappingdispatchactionpublic class mappingdispatchaction extends dispatchactionThe execution of corresponding methods is determined by the parameter name in actionmapping. Note that unlike lookupdispatchaction, the execution of corresponding methods of lookupdispatchaction is determined by the parameter attribute in actionmapping, Struts-config.xml: <Action Path = "/savesub.pdf" Type = "org. example. subscriptionaction" Name = "subscriptionform" Scope = "request" Input = "/subscribe. jsp" Parameter = "method"/> Action: Public actionforward create (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception Public actionforward edit (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception Public actionforward save (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception Public actionforward Delete (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception Public actionforward list (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception For which you wocould create corresponding <action> tolerations that reference this class: <Action Path = "/createsub.pdf" Type = "org. example. subscriptionaction" Parameter = "CREATE"> <Forward name = "success" Path = "/editsubscription. jsp"/> </Action> <Action Path = "/editsubtasks" Type = "org. example. subscriptionaction" Parameter = "edit"> <Forward name = "success" Path = "/editsubscription. jsp"/> </Action> <Action Path = "/savesub.pdf" Type = "org. example. subscriptionaction" Parameter = "save" Name = "subscriptionform" Validate = "true" Input = "/editsubpipeline. jsp" Scope = "request"> <Forward name = "success" Path = "/savedsubscribe. jsp"/> </Action> <Action Path = "/deletesub.pdf" Type = "org. example. subscriptionaction" Name = "subscriptionform" Scope = "request" Input = "/subscribe. jsp" Parameter = "delete"> <Forward name = "success" Path = "/deletedsubscribe. jsp"/> </Action> <Action Path = "/listsubscriptions" Type = "org. example. subscriptionaction" Parameter = "list"> <Forward name = "success" Path = "/subscriptionlist. jsp"/> </Action> |