Learn struts (4) -struts controller components

xiaoxiao2021-03-06  113

Struts' controller components are mainly completed:

1. Accept user request

2. According to the user request, call the appropriate model assembly to perform the corresponding business logic.

3. Get business logic execution results.

4. Select the appropriate view component to return to the user based on the current state and the business logic execution.

Note: From the above process, the control components mentioned above should focus on the process of the process, and the specific business logic is assigned to the corresponding model components. For the controller components (ActionServlet, RequestProcessor, Action), RequestProcessor has completed more process control work. The specific logic of the Process method called in the ActionServlet is also existing in the RequestProcessor component. It is also worth noting that for each application, there can be only one ActionServlet, and there are multiple independent requestProcessor corresponding to each sub-application.

Action class:

The Action class is a bridge between user requests and business logic. Each Action acts as a business agent for the customer.

Use the built-in Struts Action class:

1. Org.apache.struts.Actions.Dispatchaction class:

Typically, only one business operation can only be completed in an Action class. If you want to complete a set of related business operations in the same Action class, you can use the Dispatchaction class. For example, business operations associated with shopping cart include: view shopping carts, add goods, modify products and quantities.

When configuring the DispatchAction class, you need to set the Parameter property to "Method".

When the user requests access to the dispatchaction, the Method request parameters should be provided, for example:

http: // localhost: 8080 / netstore / action / cart? method = additem & id = 2

2. Org.apache.struts.Actions.lookupdispatchaction class:

Usually lookupdispatchaction is primarily applied to multiple submission buttons in a form, and these buttons have a common name, the names of these buttons, and the specific actionMApping parameter properties.

When configuring lookupdispatchaction, you should set the parameter property to "action" in the element, which is consistent with the Property property of the tag.

Use TOKEN to resolve repeated submission

Utilities Class: Org.apache.struts.UTIL. *

转载请注明原文地址:https://www.9cbs.com/read-100343.html

New Post(0)