Walkthrough of action in Struts framework

Source: Internet
Author: User

1. Full 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 actionservlet of struts receives a request, It then navigates to the corresponding mapping (map) based on the configuration of the Struts-config.xml, and then creates a new form instance if the form is scoped to request, or if the form is not found in the defined scope, and then the form instance is called. () method, and then place the parameters in the form into the form, if the Validate property is not false, call the Validate () method, or if validate () returns a Non-empty actionerrors, will be transferred to the URI specified by the input property. If an empty actionerrors is returned, execute the Execute () method of the action to determine the target URI based on the returned Actionforward.

The effect is that execute () executes only after the Validate () succeeds, and the input property specifies a URI.

2. Only the form action

<action path="/aFormOnlyAction"
type="org.apache.struts.actions.ForwardAction"
name="someForm"
input="someJSP.jsp"
parameter="someOtherJSP.jsp"
/>

First, struts will search for someform in the defined scope, reuse if found, and create a new instance if it is not found; When you get the form instance, call its reset () method, and then put the parameters from the form into the form, if the Validate property is not false , the Validate () method is invoked, and if validate () returns a Non-empty actionerrors, it will be forwarded to the URI specified by the input property, and if an empty actionerrors is returned, go to the target URI specified by the parameter property.

The effect is that no action class can store our business logic, so all the logic that needs to be written can only be written to the reset () or validate () method of the form. The role of validate () is to authenticate and access the business layer. Because the action map here does not include forward (and meaningless), it cannot be redirected, only the default forward. This form-only action can be used to process data acquisition and forward to another JSP to display.

3. Action-only action

<action path="/anActionOnlyAction"
type="somePackage.someActionClass">
input="someJSP.jsp"
<forward name="successful" path="someJSP.jsp"/>
<forward name="failed" path="someOtherJSP.jsp"/>
</action>

First, Actionservlet receives the request, obtains an action class instance, invokes the Execute () method, and then actionforward the Forward,forward to the specified URI or action in the configuration based on the return.

The effect of this is that no form instance is passed in to the Execute () method, so execute () must get the parameters from the request itself. The action can be forward or redirected. This action does not handle requests submitted through HTML form, and can only handle linked-style requests.

4. Only the JSP action

<action path="/aJSPOnlyAction"
type="org.apache.struts.actions.ForwardAction"
parameter="someOtherJSP.jsp"
/>

First, Actionservlet invokes the Forwardaction execute () method upon receipt of the request, and execute () forward to that URI based on the configured parameter property value.

The effect is that no form is instantiated, the more realistic scenario may be that the form is defined at the higher level of the request, or that the action is used to act as a system parameter after the application is compiled, only to change the configuration file without having to recompile the system.

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.