Working principle of Struts1
1. Initialization: The overall controller ActionServlet of the struts framework is a Servlet, which is stored on the web. configured in xml to automatically start the Servlet, at startup the Controller will read the configuration information of the configuration file (struts-config.xml), initialize the corresponding objects for different modules in struts. (Object-oriented Thinking)
2. Send a request: the user submits a form or a request to the WEB server through a URL. The requested data is transmitted to the web server over HTTP.
3. form filling: The overall struts controller ActionServlet puts the data in the member variable of the corresponding form object when the user submits the request.
4. Dispatch request: the Controller distributes the request to a specific Action based on the configuration information object ActionConfig, and the corresponding formBean is sent to the excute () method in the Action.
5. Business Processing: Action generally only contains one excute () method. It is responsible for executing the corresponding business logic (calling other business modules) and returning an ActionForward object. The server forwards data through the ActionForward object.
6. Return response: Action returns a target response object to the total controller for different results of business processing.
7. Search for response: the total controller processes the target response object returned by the business based on the Action and finds the corresponding resource object, which is generally a jsp page.
8. Response User: The target response object passes the result to the resource object and displays the result to the user.
Advantages and disadvantages of Struts1 (why use strust1)
1. Advantages:
① Open-source framework with clear structure
② Is the classic Implementation of MVC (MVC is an idea, not a technology)
③ Handle exceptions to achieve internationalization
④ Powerful tag Library
⑤ Solved the problem of a large number of JAVA code on the JSP page, which is easy to maintain
⑥ It will be automatically submitted in formBean and will not be obtained using the traditional get or set methods.
2. Disadvantages:
① Complicated configuration
② Inconvenient Test
③ Dependency on web containers
④ Action is a singleton mode and must be set to thread security
Working principle of Struts2
[V X サ Z ^? -Why? -Why? '1 z ?? ') Why does mz pull the cursor? Too many threads ?? '> ?? '~ (. B? -Zookeeper ?? '> ?? -Zookeeper? J? Comment 'items? 'Taobao? Why? '"{Too many-l limit @ r? Why 1z? -Why ?? When there are 6 rough marks + k marks? K mark 6n asthma l? K marks 6n e j Yi forging Fu Yi Yu + k marks 6 v argon pressure forging? N? z meals? Why? S? Forging qJ forging %x % z? J. Forging question? @ R? K mark 5? K marks 6 Ji Xiao ^ ?? I'm sure that Qz has been written into € r. Why are n chunks removed? Too many else j {? 'N' allowed then '*' n? Z? Too many tasks? M j & v j? C &? Sudden and sudden v peak and wide v peak x crown-padded dolphin x crown-crowned Yunnan Province j branch 8 branch yellow bone j branch yao fu w too many then n wear? Primary iR Ω mark? K branch 8 branch "http://www.bkjia.com/kf" target = "_ blank" class = "keylink"> programming, can be supervised and controlled for a certain type of objects (that is
Call the specified module before and after calling the specific methods of such objects) to expand the function of a module. These are all through
Configuration class.
Spring aims: to make the relationship between objects (modules and modules) not be associated by code.
Managed (Spring dynamically assembles objects through reflection based on these configurations)
Remember: Spring is a container. Only objects in the container can have the services and functions provided by Spring.
The most classic design pattern used in Spring is the template method pattern. (I will not introduce it here. It is a very common design model)
There are many configurations in Spring, which are hard to remember, but the essence of Spring is nothing more than the above two points. After understanding the above two points, we have basically mastered Spring.
Spring AOP and IOC
I. IoC (Inversion of control): control Inversion
1. IoC:
Concept: control is changed from the object to the container. The Container creates an instance based on the configuration file and creates dependencies between instances.
Core: bean factory; in Spring, each instance created by bean Factory is called bean
2. AOP (Aspect-Oriented Programming): Aspect-Oriented Programming
1. Proxy methods:
Static Proxy:
L write proxy classes for each specific class;
L compile a proxy class for an interface;
Dynamic Proxy:
Write an InvocationHandler for one aspect, and then use the Proxy class in the JDK reflection package to dynamically generate the corresponding Proxy class for various interfaces.
Advantages and disadvantages of Spring
It is an open-source project and is currently very active. It is based on the IoC (Inversion of Control, reverse Control) and AOP architecture multi-layer j2ee system framework, but it does not force you to use Spring in each layer, because it is very modular and allows you to choose to use one of its modules as needed; it implements very elegant MVC and provides unified interfaces for different data access technologies. IoC makes bean Assembly easy, provides concise AOP and implements Transcation management accordingly.
Advantages
A. Spring can effectively organize your intermediate layer objects, whether or not you choose to use EJB. If you only use Struts or other frameworks specially designed for J2EE APIs, Spring is committed to solving the remaining problems.
B. Spring can eliminate the excessive use of Singleton, which is common in many projects. Based on my experience, this is a big problem. It reduces the testability and object-oriented level of the system.
C. By processing configuration files in the same way between different applications and projects, Spring can eliminate the need for Attribute files in various custom formats. I was puzzled by the magic attribute or system attribute that a class was looking for. So I had to read Javadoc or even the source code? With Spring, you just need to look at the JavaBean attribute of the class. The use of Inversion of Control (discussed below) helps to simplify the process.
D. by reducing the cost of interface programming rather than class programming to almost none, Spring can promote good programming habits.
E. Spring is designed to minimize the reliance on its APIs for Applications created using it. Most business objects in Spring applications do not depend on Spring.
F. applications built using Spring are easy to perform unit tests.
G. Spring makes the use of EJB an implementation choice, rather than an Inevitable Choice of application architecture. You can use POJOs or local EJBs to implement business interfaces without affecting the calling code.
H. Spring helps you solve many problems without using ejbs. Spring can provide an EJB replacement, which is suitable for many web applications. For example, Spring can use AOP to provide declarative transaction management instead of using EJB containers. If you only need to deal with a single database, you do not even need a JTA implementation.
I. Spring provides a consistent framework for data access, whether using JDBC or O/R mapping products (such as Hibernate ).
Spring does allow you to solve your problem through the simplest and most feasible solution. This is of great value.
Disadvantage: jsp requires a lot of code, the controller is too flexible, and a public controller is missing