Read Struts-1.3.5 User Guide 1-building model components again

Source: Internet
Author: User
Part 1 Building Model Components
1. model is structured on JavaBean. This section mainly describes a variety of JavaBean (by function), but no matter what the JavaBean, there are four types of scope (the so-called scope refers to the life time and visibility of JavaBean ):

Page -- beans is only visible in one JSP page, and lifetime is the current request (at the underlying level, the bean instance is the local variable in the service method)

Request -- beans are visible in a JSP page and included in the JSP page, or all JSP and Servlet in the past are visible. At the underlying layer, this bean is an attribute of the request object. All the JSP and Servlet involved in the request are visible to the bean. Lifetime is also the request

Session -- no more
Application -- no more

2. actionform beans, or form bean for short. A Class inherited from the actionform class, used to store form data on the webpage. Strictly speaking, one bean should be prepared for each form. Of course, multiple forms can share one bean, but this is not recommended. Form Bean is a JavaBean with scope (as above ). At the beginning of a request, some operations will be done in form Bean first, and then transferred to the execute method of action class for processing. Struts will do the following in this process:

(1). Struts check whether the formbean instance of the form exists in the scope specified by form bean.
(2) If no, create one.
(3) For each parameter in the request, call the Set Method of the corresponding formbean and assign the parameter value to the member variable corresponding to the formbean.
(4). Pass the formbean instance to the execute method of the action class

We can share a formbean among multiple forms. For example, for a wizard-type interface, wizard has many steps, and each step has a form, in this case, we can create a formbean to accommodate all form elements. There is no need to design a formbean for the form in each step. Of course, how to design formbean is exactly what developers mean. struts does not care about it.

3. system state beans. This Javabean is used to store some system and user information. For example, after a user logs in, we put the user information in a bean and put the bean in the session (scope is Session), because user information is used in many places, in this way, you can conveniently obtain the information at any time. This is also a type of JavaBean that is frequently encountered. The document also mentions that this bean can be made persistent, for example, stored in the database. In this way, it can be used as needed, load/detach the bean instances at any time in the server's memory -- this is like the state bean in EJB.

4. business logic beans. Needless to say, it stores the bean of the operation logic. Generally, good design requires that these beans be completely isolated from HTTP. For example, the Code such as import javax. servlet. * should not be seen in the bean code. Generally, HTTP is stripped off through the action class, and information is sent to logic bean for processing.

5. dynabeans. the dynamically generated bean can generate bean instances on the server without writing code by configuring some XML, which can reduce the amount of code in many ways, it will also be easy to modify in the future. This is basically from the beanutil project of Apache.

6. commons chain. This is something that we didn't have before. We can link a processing process in chain mode. This is also a concept and practice proposed in the design pattern. For a request, many objects are processed in a chain. First, the caller of the chain does not need to know which objects are in the chain and what these objects are doing. Second, the logic can be put to the chain in a loose way, and the objects in the chain are loosely connected. Finally, we can easily adjust the processing logic on the chain without modifying the call logic of the chain invoker.

In struts, the processing logic for an HTTP request is a chain, which consists of many objects and processes their respective parts. The Struts-based request processing chain is based on the project-chain of Apache Jakarta. If you are interested, take a look at this project:

Http://jakarta.apache.org/commons/chain/

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.