Struts Quick Start (Five End)

zhaozj2021-02-11  193

Initialize an actionform object with formtag

This section mentioned earlier, the action URL in the HTML form is mapped to a configuration, and is mapped to a configuration. The URL made by the action attribute in the FormTag is converted to a path structure URL determined in in the deployment descriptor. For expanded mappings, this means that resource extension is the same as the specified. So, a form URL EDITCUSTOMERPROFILE? Customertype = preferred is converted to /EditCustomerProfile.do?customertype=preferred. FORMTAG Call the RequestUtils.createActionform (...) method, find an actionformbean configuration object (ActionformBean is the runtime performance of the element), its name matches the specified name of the corresponding . A new ActionForm instance is built using the element Type property; when the ActionForm instance is not found within the specified activity range, a new instance is established, otherwise formtag calls the existing form bean's actionform.reset ( ...) method to clear and prepare form data to accept the next request. This activity range is specified by the scope attribute in the element; the new ActionForm instance or the existing reinitialization instance is saved within the specified activity range using the Name property.

Save form data with ActionForm

Actionform derived objects are used to save the parameters of the request object, so they are closely linked to the user. A subclass of an ActionForm is a method for accessing the HTTPSERVLETREQUEST object parameter attribute JavaBean. If the ActionForm object is established by FormTag, the RequestProcessor will access the form from the developed activity range in the later FormTAG form translation request; the form you want to obtain is identified by the relevant action mapping. RequestProcessor will then rearrange the form attribute, populate the form with the request, and then call the Validate (...) method of the form object to perform the server-side user input verification. The validate (...) method is called only when the Validate property is set to TRUE only in the ActionMapping object; this is the default behavior. Request.getParameterValues ​​(Parameters) is used to get a string [] object, which is used to form a form fill; the result of the verification should be an ActionerRors object, with org.apache.struts.taglib.html.errostag to display the verification error to the user. ActionForm can also be used to save the current user will be referenced by an intermediate model state that references referenced by a view.

An ActionForm class can also be established by RequestProcessor. This occurs in a form that is completed forward to a URL, which is mapped to the controller servlet rather than the form properties specified by JSP and corresponding action mapping. In this case, if you don't find it within the specified activity range, the RequestProcessor will try to find a form bean that could result in a new ActionForm object. The ActionForm object is found in the specified activity range of the name property of the element; when a form object is found by RequestProcessor, it is passed to the execute (...) method of the requesting processor. An ActionForm object can also be established by requesting processors. The form object establishment is to provide an intermediate model state to use the request range JSP; which will ensure that the object does not still exist after the validity expires. By default, all forms are saved as sessions. The presence of the form object in the session may result in waste memory, the same, the request processor must track the lifecycle of the form object saved in the session. A good capture form data is to use a separate form bean for related forms across multi-user interactions. Form beans can also be used to store intermediate model states that can be changed by custom tags during feedback. The label usage is avoided in the view, so it is a good task division, the web production group mainly handles the flag, and the application development group mainly handles the Java code. Label factors exit logic accessed the intermediate model status; when accessing nested objects or when this logic can be complex when listed by aggregate. Establish an actionform with dynamic properties

A DynaActionForm object is an object with a dynamic property collection. DynaActionForm extends ActionForm, which allows you to create a form object by declaring a struts-config.xml, as follows:

Type = "org.apache.struts.action.dynaactionform">

RequestProcessor is established in the same way as ActionForm, populates and verifies DynaActionForm, for example, the parameters of the request object are filled into the DynaActionform in the element; other parameters are simple.

to sum up

Implementing the MVC Semantics (Semantics) for an HTTP protocol based on request / response requires significant time and effort. Select a suitable architecture to solve this problem with a leading project, allowing architects and developers to focus on transaction semantics rather than integration. Struts also provides adequate models such as Struts Validator to declare form validation, TILES to gather a view; these models enhance architecture and greatly simplify design and development tasks. Struts more information and related configurations and installations can be found at http://jakarta.apache.org/struts/userguide/index.html. Because Struts development is an ongoing development, some implementations will also be changed when you read this article, so it is the best version of the release of http://jakarta.apache.org/struts And update to make up this chapter.

reference

[CORE] Core J2EE Patterns by Deepak Alur et. Al. (Prentice Hall, 2001) [GOF] Design Patterns By Erich Gamma et. Al. (Addison-Wesley, 1995)

After completing, the first translation is also to deal with the exam ~

Turn it, everyone is forgiven ~

Ice cloud translation, please let us know.

IceCloud@sina.com

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

New Post(0)