SSH-Struts (III)-ActionForm
ActionForm is used to encapsulate the user's request data, that is, the data that the user enters on the page. It acts as a transport. In order to understand ActionFrom in a three-dimensional way, we can look at it from two perspectives:
From the perspective of encapsulated data content, Entity objects are usually created based on database tables. In other words, Entity objects face databases. ActionForm faces the data displayed on the interface. From the perspective of function, we know that data is stored in the Session or request in units of page elements before Struts is introduced. The trouble is that it is not convenient to retrieve data, and it is not object-oriented. However, ActionForm makes the data that the user inputs does not correspond to the object, and stores the data in the Session or Request as an object.
The action flow of ActionForm roughly describes the action flow of ActionForm through a sequence chart. Because a class image is not first painted, it is described in text directly. More than enough!
Scope and life cycle the so-called life cycle is the whole process of ActionForm from creation to extinction. From the above sequence diagram, we can basically see a rough picture. There are two types of lifecycle of ActionForm: request and session. If the ActionForm exists in the request range, it is valid only for the current request lifecycle. When a request is forwarded from one Web component to another, ActionFZ does? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> encrypt/7O8cb3sNHP7NOmveG5 + 7e1u9i4 + L/weight + zbvhsbvP + weight/weight + weight/J0tS4 + L + weight + examples/W + qOsy/y88ruvwcu0 + examples/UtcTIsbXjoaPK18/examples + zb/examples + examples/cG/o6E8YnI + examples/examples + Cgo8aDE + crop + crop + sLroaPS1M/CzqrKvsD9o7o8YnI + CiAgICAgIDxwcmUgY2xhc3M9 "brush: java; "> Topic-VO/DTO: the so-called VO and DTO are actually two types of data transmission objects, and ActionForm is one type of VO, so this content is fully introduced here.
VO: value object/view object performance Layer object
It mainly corresponds to Data Objects displayed on pages (web Pages/swt and swing interfaces. It can correspond to or not to a table, depending on the business needs.
In struts, to use ActionForm for VO, a conversion is required because the PO is object-oriented and the ActionForm corresponds to the view, you can use the copy method of BeanUtils to combine the attributes of several PO to display into an ActionForm.
DTO (TO): Data Transfer Object Data transmission Object
When cross-process or remote transmission is required, it should not contain the business logic. For example, if a table has 100 fields, the corresponding PO has 100 attributes (in most cases, data in DTO comes from multiple tables ). However, the view layer only needs to display 10 fields, and there is no need to pass the entire PO object to the client. In this case, we can transmit data to the client with only the DTO of these 10 attributes, in this way, the server-side table structure will not be exposed. After the client is reached, if this object is used for display on the corresponding interface, then its identity will be changed to VO.
Summary: ActionForm encapsulates the data from the user input to make the program more object-oriented. It plays the role of a shipping tool!