[Java] SSH Frame Note _1_ Frame Analysis + Environment Building + instance source download

Source: Internet
Author: User

First of all,SSH is not a framework, but a multi-framework (struts+spring+hibernate) Integration , is now a popular web application open-source Integration Framework for the construction of flexible, A multi-tiered Web application that is easy to scale .

The systems that integrate the SSH framework are divided into four tiers: presentation layer, business logic layer, data persistence layer, and Domain module layer (entity layer).

Struts, as the overall infrastructure of the system, is responsible for the separation of MVC, controlling the business jump in the model part of the struts framework, and supporting the persistence layer with the Hibernate framework . Spring, on the one hand , is a lightweight IoC container that is responsible for locating, locating, creating, and managing dependencies between objects and objects, on the other hand, enabling Struts and Hibernate to work better.

The basic business process for building a system by SSH is:

1, in the presentation layer, first through the JSP page interactive interface, responsible for transmitting requests (request) and receive response (Response), and then struts according to the configuration file (Struts-config.xml) Delegate the request received by Actionservlet to the appropriate action handler.

2. in the business layer, the spring IOC container that manages the serviced component is responsible for providing the business model component to the action and the component's collaboration Object data Processing (DAO) component to complete the business logic and to provide transaction processing, Buffer pools and other container components to improve system performance and ensure data integrity.

3 . In the persistence layer, it relies on Hibernate's object mapping and database interaction, processing the data requested by the DAO component, and returning the processing result.

The above development model not only realizes the complete separation of the view, controller and model, but also realizes the separation of the business logic layer and the persistence layer. This way, no matter how the front-end changes, the model layer requires little change, and the database changes will not affect the front end, greatly improving the reusability of the system. And because of the small coupling between different layers, it is advantageous to the team members to work in parallel, greatly improving the development efficiency.

Let's take a look at the three frameworks that make up SSH

First, Spring

1. What is Spring?

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

2. Features of Spring

Specific self Baidu Bar

All of these features of spring enable you to write cleaner, more manageable, and easier-to-test code

3. Why use Spring?

The above features of spring allow developers to use basic javabean to accomplish things that were previously only possible by EJBS. However, the use of spring is not limited to server-side development. From the standpoint of simplicity, testability, and loose coupling, any Java application can benefit from spring.

Second, Struts

1. What is struts?

Using Java servlet/jsp Technology, it realizes the application framework of MVC design pattern based on Java eeweb application, and it is a classic product in MVC Classic design pattern.

2, the core composition of Struts1

In Struts1, a Servlet named Actionservlet acts as the controller, and forwards the view according to the configuration file that describes the struts-config.xml of the model, view, and Controller counterpart (view) Request, assemble the response data model.

In the model part of the MVC, it is often divided into two main subsystems (the internal data state of the system and the logical action of changing the data state), the two conceptual subsystems correspond to the Actionform and action two in Struts 1 respectively. Here, Struts 1 can be combined with a variety of standard data access technologies, including Enterprise Java Beans (EJB), JDBC, and JNDI.

In the view side of Struts 1, in addition to using standard JavaServer Pages (JSP), there are a number of tag library uses available, as well as integration with other presentation Layer component technologies (products), such as Velocity templates,xslt such as

By applying the Struts framework, end users can place most of their concerns in their own business logic (Action) and the mapping relationship configuration file (Struts-config.xml).

3, the basic implementation process of STRUTS1

See the basic work flow of struts

4. What is Struts2

Struts 2 is the next generation of struts and is the new Struts 2 framework that was combined with struts 1 and webwork technology. Its new Struts 2 architecture differs greatly from the architecture of struts 1. Struts 2 takes the webwork as the core and uses the interceptor mechanism to process the user's request, so that the business logic controller can be completely detached from the SERVLETAPI, so struts 2 can be understood as the webwork of the new product

5. STRUT2 Architecture

Analytical:

When the Web container receives the request (HttpServletRequest) It passes the request to a standard filter chain including the process (Actioncontextcleanup) filter, and then passes through the other filters (Sitemesh, etc),

Next you need to call the Filterdispatcher core controller, and then it calls Actionmapper to determine the request that Action,actionmapper returns a Actionmaping object that collects the action details.

Next Filterdispatcher delegate control to Actionproxy,actionproxy call Configuration Manager (ConfigurationManager) to read configuration information (Struts.xml) from the configuration file. The Actioninvocation object is then created, and Actioninvocation invokes the configured interceptor (Interceptor N) in turn before invoking the action. Once the result of the execution returns the result string actioninvocation is responsible for finding the result string corresponding to (result) and then executing this result will call some template (JSP)

To render the page, after which the Interceptor (Interceptor N) responds to the last response (the reverse of the order and the Action Execution) (HttpServletResponse) The filters and (core controllers) (Filterdispatcher) configured in Web. XML are returned.

6. Why use struts?

First, Struts is an implementation of MVC, which uses servlets and JSP tags (which belong to the Java EE Specification) as part of the implementation. Struts inherits the characteristics of MVC and makes corresponding changes and expansions according to the characteristics of the Java EE , weakening the coupling between the business logic interface and the data interface, and making the view layer more changeable .

In addition, struts has a page navigation function, which makes the system's context clearer. Through a configuration file, you can grasp the connection between the parts of the whole system, which is of great benefit to the later maintenance. This is especially true when another group of developers took over the project.

7. The difference between Struts1 and Struts2

See "Struts1 and Struts2"

Third, Hibernate

1. What is Hibernate?

Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking. Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary of all, hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence

2.Hibernate Core composition

It's not going to unfold.

3.Hibernate Basic execution Process

Why use Hibernate?

1. The code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer.

2, Hibernate is an excellent ORM implementation. He simplifies the coding of the DAO layer to a large extent, freeing the software developers from the extensive programming of the same data persistence layer, and making the development more object-based.

3, good transplant, support a variety of databases, if you change a database as long as the configuration file configuration can be changed, do not change hibernate code.

4, support transparent persistence, because hibernate operation is pure (Pojo) Java class, did not implement any interface, no intrusion. So it's a lightweight framework.

Finally attach the example of SSH1 and SSH2 frame, click to download

SSH1 Frame Build Example (Spring2+struts1+hibernate3) with older versions, see the code for comments

SSH2 Framework Construction Example (spring3.2+strust2.3.4+hibernate4.2) all with the latest version, see the code in the comments

Development environment Building, refer to my other blog

"Win7" + Eclipse (+ tomcat7) + JDK7 (64) Development environment Configuration

Some instructions: Ask for the code of the mailbox, I have basically sent out, if there is a leak, please contact me. Or you want to go to the csdn download page to download. If the speed is slow, you can go here http://Pan.baidu.com/s/1eqh7fxodevelopment environment configuration. http://blog.csdn.net/shan9liang/article/details/8807784in the war, find application.-Common.xml. Modify the data source to specify your own database.  After the project is deployed, the table is automatically mapped. <!--with data source-<bean id="DataSource" class="Org.apache.commons.dbcp.BasicDataSource"Destroy-method="Close"> <property name="Driverclassname"Value="Oracle.jdbc.driver.OracleDriver"/> <property name="URL"Value="Jdbc:oracle:thin: @localhost: 1521:orcl"/> <property name="username"Value="SSH"/> <property name="Password"Value="SSH"/> </bean>The above is the configuration of Oracle. If you are using a different database, in the Lib directory, add the driver package.  and modify the data source. Highly recommended: https://CODE.CSDN.NET/SHAN9LIANG/TGBThis is in CSDN code managed, using SSH to build an attendance management system, MAVEN project, than the original one more standardized, recommend this, and I will continue to update, gradually join various mainstream framework, believe me. But not the Eclipse project, you need to import eclipse by hand, and have recently liked to use IntelliJ. It is recommended to use Git clone directly. 

[Java] SSH Frame Note _1_ Frame Analysis + Environment Building + instance source download

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.