See a good article on TSS.com about the advantages and disadvantages of different combinations of Action and ActionForm in Struts. I will digest it and sort it out for your reference. Original article title: Struts action mappings: Divide Et Impera, Author: Michael juravlev. URL on the TSS: http://www.theserverside.com/articles/article.tss? L = StrutsActionMapping
Note: reading this article requires some Struts basics.
Note: The lower-case action in the text does not necessarily represent the specific Struts Action class, but sometimes it also refers to the overall action mapping.
[1] complete action
<Action path = "/aFullAction"
Type = "somePackage. someActionClass">
Name = "someForm"
Input = "someJSP. jsp"
<Forward name = "successful" path = "someJSP. jsp"/>
<Forward name = "failed" path = "someOtherJSP. jsp"/>
</Action>
First, the Struts ActionServlet receives a request, and then locates the corresponding mapping according to the configuration of the struts-config.xml ); next, if the form is in the request or cannot be found in the defined range, create a new form instance. After obtaining the form instance, call its reset () method, then, put the parameters in the form into the form. If the validate attribute is not false, call the validate () method. If validate () returns non-empty ActionErrors, the URI specified by the input attribute will be transferred. If an empty ActionErrors is returned, execute () method of the Action to determine the target URI Based on the returned ActionForward.
The result is that execute () is executed only after validate () is successful. The input attribute specifies a URI.
[2] only Form actions
<Action path = "/aFormOnlyAction"
Type = "org. apache. struts. actions. ForwardAction"
Name = "someForm"
Input = "someJSP. jsp"
Parameter = "someOtherJSP. jsp"
/>
First, Struts searches for someForm in the defined scope. If it finds it, It is reused. If it cannot find it, a new instance is created. After obtaining the form instance, it calls its reset () method, then, put the parameters in the form into the form. If the validate attribute is not false, call the validate () method. If validate () returns non-empty ActionErrors, the URI specified by the input property will be transferred. If an empty ActionErrors is returned, the URI specified by the parameter property will be transferred.
The result is that no action class can store our business logic, so all the logic to be written can only be written to the form reset () or validate () method. Validate () is used to verify and access the business layer. Because the action ing here does not include forward (and it doesn't make sense), you can only use the default forward instead of redirection. This form-only action can be used to process data acquisition and forward to another JSP for display.