Different combinations of Action and ActionForm in Struts

Source: Internet
Author: User

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.

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.