Ssh faq (struts, Hibernate)

Source: Internet
Author: User

How struts1 works
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
How struts2 works
Struts2 Working Principle

1. The client initializes a request pointing to a servlet container (such as Tomcat ).
2. This request goes through a series of filters (these filters have an optional filter called actioncontextcleanup, which is very helpful for the integration of struts2 and other frameworks, such as sitemesh plugin)

3. filterdispatcher is called. filterdispatcher asks actionmapper to determine whether to call an action.
4. If actionmapper decides to call an action, filterdispatcher submits the request processing to actionproxy.
5. actionproxy asks the framework configuration file through Configuration Manager and finds the action class to be called.
6. actionproxy creates an actioninvocation instance.
7. The actioninvocation instance uses the naming mode for calling. Before and after the action is called, the call of the relevant Interceptor (intercepter) is involved.
8. Once the action is executed, actioninvocation is responsible for finding the corresponding return result based on the configuration in struts. xml. The returned result is usually a JSP or freemarker template to be represented (but not always, or another action chain. You can use the tag inherited from the struts2 framework in the Process of representation. Actionmapper needs to be involved in this process

All objects (actions, results, interceptors, etc.) in the above process are created through objectfactory.
Advantages and disadvantages of struts2 (that is, why struts2 is used)
Struts2 automatically performs verification. There are many more such as international resource files.
In the development of struts2, if you have never used any frameworks, you can also use quick learning to join struts2 application development because it is simple enough.
A large number of interceptors:
Struts2 itself provides a large number of reusable interceptors, such as the type conversion Interceptor. Many times we get parameters from the page. In this case, it is of the string type and we need to manually.
Plug-in-based framework:
Struts2 is a plug-in-based framework. Many practical plug-ins are provided in the community, such as jfreechat/JSON. Using these plug-ins can simplify our development and speed up development.
The biggest drawback of struts2 is that it does not support many web servers well. For example, in WebSphere 5.5, Weblogic8.1 and earlier versions, it is very difficult to query and use the latest version.
Support for multiple views:
Support for multiple views: JSP, freemarker, and veloctiy. You can even easily modify it to support PDF. You can support multiple views in the same project.
More modular:
Compared with struts1.x, struts2 is more modular and allows you to easily split configuration information into multiple files based on functional boundaries for management and collaborative development.
Integration with spring:
Compared with struts1.x, struts2 does not have to write Singleton by itself, further reducing the coupling between programs. Within struts2 itself, it reduces the coupling of the framework itself.
Pojo-based ease of testing:
In struts1.x, I need mock to output these two HTTP objects, which makes it difficult for us to compile the unit test of action. Compared with struts1.x, struts2 action no longer depends on
 
Httpservletrequest and httpservletresponse Objects make it easier for us to write unit tests for actions.
How hibernate works
1. Read and parse the configuration file
2. Read and parse the ing information and create sessionfactory
3. Open sesssion
4. Create transaction Transation
5. Persistent operations
6. Submit the transaction
7. Disable session
8. Disable sesstionfactory

Advantages and disadvantages of Hibernate
Advantages:
1: Hibernate is an open-source framework based on ORMapping technology. It encapsulates JDBC in a lightweight manner and uses Object-oriented Thinking to manipulate databases.
2: hibernate provides session cache and second-level cache, improving the performance of systems that do not require complex queries.
3: Low intrusion Design

Disadvantages:
1: The learning cost of Hibernate is too high.
2: complex SQL queries (Statistics) are not suitable ).
3: not suitable for a large number of aggregation operations (stored procedures)
Strengths and weaknesses:
1. SQL statements that do not need to be compiled (JDBC is not required). You only need to operate on the corresponding objects to store, update, delete, and load objects, can improve production efficiency;
2. Because hibernate only requires objects to be operated, our development is more object-oriented;
3. Use hibernate for better portability (as long as you use the hibernate standard for development and change the database, you only need to configure the corresponding configuration file and do not need to perform other task operations );
4. hibernate implements transparent Persistence: when an object is saved, this object does not need to inherit any classes in Hibernate and implement any interfaces, it's just a pure object-called a pojo object (the purest object-this object does not inherit any class of the third-party framework and any interface to implement it)

5. Hibernate is a non-invasive framework, which is generally called a lightweight framework.
6. Easy to test the hibernate code.

Related Article

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.