Struts Quick Start (2)

zhaozj2021-02-11  213

Struts MVC Semantics

We started from the key Struts abstraction, this is the core of its MVC architecture. Struts implements MVC mode using the Service to Worker mode. [Core]

Controller object

The controller is implemented by the ActionServlet class. It provides a central location to process all of the terminal requests. This provides a clearer division for the control layer of the handling view and navigation management, and the model access and operation is left to a dedicated request processor. All submitted requests are mapped to the central processor, and their configuration description is as follows:

Action

org.apache.struts.Action.ActionServlet

All requests URI exists with * .do mode and map to this servlet, which is configured as follows:

Action

*. do

The request URI of this mode meets the following format:

http://www.my_site_name.com/mycontext/Actionname.do

The above mapping is called an extended mapping, you can also declare the path map, using / * ending mode, as shown below:

Action

/ do / *

The request URI of this mode meets the following format:

http://www.my_site_name.com/mycontext/do/Action_name

The resource logic map described above allows you to modify the resource mapping in the configuration file without modifying any application system code. This mapping scheme is also used in MULITPLEXED RESOURCE MAPPING. The controller provides a set of access points for all representation layer requests. The controller distinguishes each submitted request to the RequestProcessor, whose turnt sends a request to the related form bean for a form authentication, and then issues to a request processor to access the model. The abstract concept provided by this controller reduces the difficulties of developers to build public application system services, such as management views, sessions, and form data. Developers support a general mechanism such as errors and abnormal processing, navigation, internationalization, data verification, data conversion, and more.

In Struts 1.1, the controller needs to read the configuration in the init () method. This configuration controls the behavior of the architecture, contains the Map of the URI to the request processor, such as using an actionMApping configuration object, setting information resources, and provides access to external resources through plugins. In fact, the process of submit request actually occurs in the processServlet commissioning all input requests to RequestProcessor.

Sender object

The RequestProcessor function is to process the request as a sender, with an instantiation (or multiplexed) a request processor and a corresponding form bean to process the request. Form bean and requesting processor's creation or exception throws the RequestProcessor process and affects the view management feature of RequestProcessor. Form Bean Assist RequestProcessor saves form data and / or prepares the intermediate model data necessary for the view. RequestProcessor uses the declared struts-config.xml file, as shown below, such as a request processor for a particular request.

Type = "packagename.editcustomerProfileAction"

Name = "CustomerProfileform"

Scope = "request" />

Type = "packagename.customerProfileform" />

All submitted requests are commissioned to the object sender of the RequestProcessor. RequestProcessor Checks the request URI to find actions, and use the information in the ActionMapping object to create a request processor instance, then call the RequestHandler.execute (...) method. Request the execute (...) method task in the processor is to use each other with the application model. The request processor returns to RequestProcessor based on the results. RequestProcessor will use the ActionForward object to call the next view by executing RequestDispatcher.Forward (...) or Response.sendRedirect (...).

(to be continued..)

Ice cloud translation, please let us know.

IceCloud@sina.com

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

New Post(0)