SSH Small Talk

Source: Internet
Author: User
Tags aop

Going to see spring as one of the three big frames, has been puzzled by what she has to do with it. Why do you use spring? Think back to the past year, spend a lot of time to see struts, Hibernate, always go to what they have to use, how to use, but never to think about why to use them. Do you have to use SSH? So it took some time to collect information (mostly from the internet, citing too many citations, not to be identified.) )。

SSH represents 3 kinds of frameworks in the Java EE Project, Spring + Struts +hibernate. Struts provides the corresponding components for both Model,view and controller. Spring is a lightweight, control inversion (IoC) and aspect-oriented (AOP) container framework that is created by Rod Johnson. It is created to address the complexity of enterprise application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJB. Hibernate is an open source Object Relational mapping framework that has a very lightweight object encapsulation for JDBC, can be applied to any use of JDBC, can be used in servlet/jsp Web applications, and can replace CMP in the Java EE architecture of EJB application To complete the task of data persistence.

The STRUTS2 principle is to use interceptors so that the requests sent by your client are intercepted and processed. The interceptor has a reflex mechanism. The main function of Struts2 is to control forwarding, in the process of action, and Struts.xml configuration.

Spring actually contains a lot of knowledge, the use of IOC,AOP and so on, in fact, is a management framework of the container, you do not have to consider your new object, it will help you to do, reduce the layer and layer of coupling between the degree. Spring has a lot of ideas, and the IOC is control reversal, injection. AOP is facet-oriented, a bit like a interceptor.

Hibernate is a persistence layer framework, we usually use JDBC operation database to write SQL statements, sometimes a lot of fields will be very troublesome, so with the hibernate is very convenient, you just master the mapping relationship inside, you do not have to write SQL statements, it will help you write,   API to call it very handy. Struts

  1.Struts Frame Structure  

As shown on the right:

Struts provides the corresponding components for both Model,view and controller.

In the right figure, Actionservlet, this class is the core controller of struts, which is responsible for intercepting requests from users.

Action, which is typically provided by the user, is responsible for receiving requests from Actionservlet and invokes the business logic method of the model to process the request based on the request, and returns the processing result to the JSP page display.

2. TheModel section consists of Actionform and JavaBean, where actionform is used to encapsulate the user's request parameters, encapsulated as Actionform objects, which are actionservlet forwarded to the action, The action processes the user's request according to the request parameters inside the Actionform.

JavaBean encapsulates the underlying business logic, including database access.

3. This part of theView section is implemented using JSP.

Struts provides a rich library of tags, through the tag library can reduce the use of scripts, custom tag library can be implemented with the model of effective interaction, and increase the reality of the function. Corresponds to the JSP portion of the above figure.

4. The controller component of thecontroller component consists of two parts-the system core controller and the business logic controller.

The system core controller corresponds to the actionservlet of the above figure. The controller is provided by the struts framework and inherits the HttpServlet class, so it can be configured as a callout servlet. The controller is responsible for intercepting all HTTP requests and then deciding whether to transfer to the business logic controller based on the user's request.

The business logic controller, which handles the user request, does not have the processing capability itself, but calls model to complete the processing. Corresponds to the action section.

Spring

  1. Introduction 

Objective: To solve the complexity of enterprise application development

Function: Use basic JavaBean instead of EJB, and provide more enterprise application function

Scope: Any Java application

In short, spring is a lightweight control reversal (IoC) and aspect-oriented (AOP) container framework.

2. Spring is lightweight both in terms of size and cost. The complete spring framework can be published in a jar file that is only 1MB large. and the processing overhead required by spring is negligible. In addition, Spring is non-intrusive: Typically, objects in a spring application do not depend on a particular class of spring.

For intrusive non-invasive, simply say what I understand. Suppose everyone wants to cram the user code into a frame. The intrusive approach is to require the user code to "know" the Code of the framework, as shown by the user code that needs to inherit the class provided by the framework. Non-intrusive does not require user code to introduce frame code information, from the class writer's point of view, does not perceive the existence of the framework.
For example:
When I used struts, I needed to inherit some of the struts classes when struts hacked into my code.
With spring, you don't need to inherit the spring-specific classes when you write some business classes, and you can use them once you've configured the dependency injection, and spring doesn't invade the code of my business class.

Intrusive allows user code to generate dependency on the framework, which cannot be used outside the framework, and is not conducive to the reuse of code. But intrusive can make it easier for users to integrate with the framework, and to make better use of the functionality provided by the framework.
Non-intrusive code is not overly dependent and can be easily migrated elsewhere. But the way in which you interact with user code can be more complex.
Both of these methods have their own advantages and disadvantages, mainly looking at the actual development of how to weigh.

3. control reversal Spring promotes loose coupling through a technology called Control reversal (IoC). When the IOC is applied, other objects that an object relies on are passed in passively, rather than the object itself creating or locating dependent objects. You can think of the IOC as the opposite of Jndi-not that the object looks for dependencies from the container, but rather that the container is actively passing the dependency to it when the object is initialized.

4. section Spring provides rich support for aspect-oriented programming, allowing for cohesive development through separation of application business logic and system-level services such as audit (auditing) and transaction (transaction) management. Application objects only implement what they should do--complete the business logic--that's all. They are not responsible (or even conscious) of other system-level concerns, such as logs or transactional support.

5. container Spring contains and manages the configuration and lifecycle of the Application object, in the sense that it is a container where you can configure how each of your beans is created-based on a configurable prototype (prototype), Your bean can create a separate instance or generate a new instance each time it is needed-and how they relate to each other. However, spring should not be confused with traditional heavyweight ejb containers, which are often bulky and unwieldy and difficult to use.

6. Frame Spring can be a complex application with simple component configurations and combinations. In spring, application objects are declaratively grouped, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, and so on) that leave the development of application logic to you.

All of Spring's features enable you to write cleaner, more manageable, and more testable code. They also provide basic support for the various modules in spring.

Hibernate

  1. Introduction  

Hibernate is an open source Object Relational mapping framework that has a very lightweight object encapsulation for JDBC, making it possible for Java programmers to manipulate the database with arbitrary object programming thinking. Hibernate can be applied in any use of JDBC, either in Java client programs or in servlet/jsp Web applications, and, most of all, hibernate can replace CMP in an EJB-ee architecture, Complete the task of data persistence.

There are 5 core interfaces of Hibernate, namely session, Sessionfactory, Transaction, query and configuration. These 5 core interfaces will be used in any development. Through these interfaces, not only can the persisted object be accessed, but also the transaction can be controlled. The following five core interfaces are described separately.

  2.Session Interface The session interface is responsible for performing crud operations on the persisted object (the CRUD task is to communicate with the database, including many common SQL statements.) )。 However, it should be noted that the session object is not thread safe. At the same time, Hibernate's session is different from the HttpSession in JSP application. Here when using the term session, in fact, refers to the hibernate in the sessions, and later will be the Httpsesion object called the user.

  3.SessionFactory Interface The Sessionfactory interface is responsible for initializing hibernate. It acts as a proxy for the data storage source and is responsible for creating the Session object. The factory model is used here. Note that sessionfactory is not lightweight, because typically a project requires only one sessionfactory, and you can specify a sessionfactory for each database when you need to manipulate multiple databases.

  4.Configuration Interface The configuration interface is responsible for configuring and starting Hibernate, creating Sessionfactory objects. During hibernate startup, instances of the configuration class first locate the mapping document location, read the configuration, and then create the Sessionfactory object.

  5.  Transaction Interface The transaction interface is responsible for transaction-related operations. It is optional, and developers can also design their own underlying transaction processing code.

  6.Query and Criteria Interface Query and the criteria interface are responsible for performing various database queries. It can be expressed using either the HQL language or the SQL statement.

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.