SSH framework Summary (Framework Analysis + Environment setup + instance source code download)

Source: Internet
Author: User

 

First, SSH is not a framework, but the integration of multiple frameworks (STRUTS + spring + hibernate). It is a popular open-source integration framework for Web applications, it is used to build flexible and scalable multi-layer Web applications.

 

The systems integrated with the SSH framework are divided into four layers: presentation layer, business logic layer, data persistence layer, and domain Module layer (entity Layer ).

 

As the overall infrastructure of the system, Struts is responsible for the separation of MVC. In the model section of the Struts framework, it controls service redirection and uses the Hibernate framework to provide support for the persistent layer. As a lightweight IOC container, spring is responsible for searching, locating, creating, and managing dependencies between objects and objects. It also enables struts and Hibernate to work better.

 

 

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

 

1. In the presentation layer, the interactive interface is first realized through the JSP page, which is responsible for transmitting the request and receiving the response, and then struts according to the configuration file (struts-config.xml) delegates The request received by the actionservlet to the corresponding action for processing.

2. At the business layer, the Spring IoC container of the management service component is responsible for providing the business model component to the action component and the collaborative Object Data Processing (DAO) component of the component to complete the business logic, it also provides container components such as transaction processing and buffer pool to improve system performance and ensure data integrity.

3. In the persistence layer, it depends on Hibernate's object-oriented ing and database interaction to process the data requested by the DaO component and return the processing result.

 

Using the above development model, Butler not only achieves the complete separation of views, controllers and models, but also achieves the separation of the business logic layer and the persistent layer. In this way, no matter how the front-end changes, the model layer requires only a very small number of modifications, and database changes do not affect the front-end, greatly improving the reusability of the system. In addition, because the coupling between different layers is small, it is beneficial for team members to work in parallel and greatly improves the development efficiency.

 

 

Next, let's take a look at the three SSH frameworks.

I. Spring

1. What is spring?

In short, spring is a lightweight container framework for IOC and AOP.

 

2. Features of spring

Baidu for details

All of these features of spring allow you to write code that is cleaner, manageable, and easier to test.

 

3. Why use spring?

The above features of spring allow developers to complete things that may have been completed by EJB only by using the main JavaBean. However, spring is not only used for server development. From the perspective of simplicity, testability, and loose coupling, any Java application can benefit from spring.

 

Ii. Struts

1. What is struts?

It uses Java Servlet/JSP technology to implement the MVC design mode application framework based on Java eeweb applications. It is a classic product in the classic MVC design mode.

 

2. Core Structure of struts1

 

In struts1, a servlet named actionservlet acts as the controller. Based on the configuration file of the struts-config.xml describing the relationship between model, view and controller) and assemble the response data model ).

 

In the model section of MVC, it is often divided into two main subsystems (the internal data status of the system and the logical action to change the data status ), the two conceptual subsystems correspond to the actionform and action in struts 1 respectively, which must inherit and implement superclasses. Here, Struts 1 can be combined with various standard data profiling technologies, including Enterprise Java Beans (EJB), JDBC, and JNDI.

 

In addition to the standard JavaServer Pages (JSP), the view end of struts 1 also provides a large number of tag libraries, at the same time, it can also be integrated with other presentation layer component technologies (products), such as velocity templates and XSLT.

 

Through the application of Struts framework, users can finally focus most of the focus on their own business logic (action) and ing relationship configuration file (struts-config.xml.

 

3. Basic Procedure of struts1

For details, see struts basic workflow.

 

4. What is struts2?

Struts 2 is the next-generation product of Struts. It is a new struts 2 framework that is merged Based on Struts 1 and webwork technologies. The new architecture of struts 2 differs greatly from that of struts 1. Struts 2 uses webwork as the core, and the interceptor mechanism is used to process users' requests. This design also allows the business logic controller to completely remove from the servletapi, therefore, Struts 2 can be understood as a webwork update product.

 

5. strut2 Architecture

 

 

Resolution:

When the Web Container receives the request (httpservletrequest), it passes the request to a standard filter chain containing flow (actioncontextcleanup) filter, and then passes through other filters (sitemesh, etc ),

Next, you need to call the filterdispatcher core controller, and then it calls actionmapper to determine the request action. actionmapper returns an actionmaping object that collects the specific information of the action.

Next, filterdispatcher delegates the control to actionproxy. actionproxy calls the Configuration Manager to read the configuration information (struts. XML), and then create an actioninvocation object. actioninvocation will call the configuration Interceptor (interceptor N) in sequence before calling the action. Once the running result returns the result string actioninvocation, it is responsible for finding the result string corresponding to (result) then, running this result will call some templates (JSP)

After the Interceptor (interceptor N) returns the final response (httpservletresponse) to the Web after it is run (the order is the opposite to that before the action is run. filters and (core controller) (filterdispatcher) configured in XML ).

 

6. Why does struts work?

First, Struts is an implementation of MVC. It uses Servlet and JSP tags (which are part of the J2EE specification) as part of the implementation. Struts inherits various MVC features and makes corresponding changes and extensions based on the characteristics of J2EE, reducing the coupling between business logic interfaces and data interfaces, and make the view layer more changeable

 

In addition, Struts provides the page navigation function to make the system context clearer. Through a configuration file, you can grasp the relationship between all parts of the system, which has great advantages for later maintenance. This advantage is especially evident when a group of developers take over the project.

 

7. Differences between struts1 and struts2

For details, see struts1 and struts2.

 

Iii. hibernate

1. What is hibernate?

Hibernate is an open source object relationship ing framework. It implements lightweight object encapsulation for JDBC, so that Java programmers can use the object programming thinking to manipulate the database as they wish. Hibernate can be used in Java client programs and Servlet/JSP web applications no matter what JDBC is used. The most revolutionary thing is that, hibernate can replace CMP in the J2EE architecture of application EJB to complete the task of data persistence.

 

2. hibernate Core Components

 

Details are not expanded.

 

3. Basic hibernate running process

 

 

Why hibernate?

1. The code of the JDBC connector database is encapsulated, which greatly simplifies the tedious and repetitive code of the data connector layer.

2. Hibernate is an excellent ORM implementation. He greatly simplifies the coding of the DaO layer, frees software developers from a large number of programming tasks related to the same data persistence layer, and makes development more object-oriented.

3. Good portability and support for various databases. Assume that you only need to change the configuration in the configuration file, without changing the hibernate code.

4. Transparent persistence is supported. Since hibernate operates purely (pojo) Java classes, no interface is implemented and no intrusion is required. Therefore, it is a lightweight framework.

 

 

Finally, attach the instances created by the SSH1 and SSH2 frameworks, and click here to download them.

The SSH1 framework builds an instance (spring2 + struts1 + hibernate3) using the old version number. For details, see stare in the code.

All SSH2 frameworks (spring3.2 + strust2.3.4 + hibernate4.2) use the latest version. For more information, see stare in the code.

 

Build a development environment and follow my blog

Win7 (64) + eclipse (64) + tomcat7 (64) + jdk7 (64) Development Environment Configuration"

 

 

Some Notes: I have sent all emails asking for code. If there are missed emails, please contact me. I hope you can download it on the csdn download page. If the speed is slow, visit http://pan.baidu.com/s/1eq?fxoto configure the environment. Http://blog.csdn.net/shan9liang/article/details/8807784 in war, locate the application-common.xml. Modify the data source and specify your own database. After the project is deployed, the tables are automatically mapped. <! -- Configure the 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> configuration. If other databases are used, add them in the Lib folder? Driver package. And modify the data source. It is strongly recommended that: https://code.csdn.net/shan9liang/tgb, which is hosted by csdn code, use SSH to build an attendance management system. The Maven project is more standardized than the original one. We recommend using this, and I will continue to update it and add it? Believe me in various mainstream frameworks .. It's just not an Eclipse project. You need to manually import eclipse. intellij is a favorite recently. We recommend that you use git clone directly.


 

 

 

 

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.