SSH framework Summary

Source: Internet
Author: User

First, SSH is not a framework, but an 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. On the other hand, it can make struts and hibernate 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, responsible for transmitting the request and receiving the response, 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.

 

The above development model 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 few changes, 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 closer 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

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

 

3. Why use spring?

With the above features of spring, developers can use basic Javabean to do things that previously could only be done by ejbs. However, spring is not only used for server-side 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, forwarding the view according to the configuration file of the struts-config.xml that describes the model, view, controller correspondence) 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 and need to inherit and implement superclasses. Here, Struts 1 can be combined with various standard data access 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, it can also be integrated with other presentation layer component technologies (products), such as velocity templates and XSLT.

 

By applying the Struts framework, end users can focus most of their attention on their own business logic (action) and ing relationship configuration file (struts-config.xml.

 

3. Basic execution process 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 is very different from that of struts 1. Struts 2 takes webwork as the core and uses an interceptor mechanism to process user requests. This design also enables 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, including the 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 requested action. actionmapper returns an actionmaping object that collects detailed information about the action.

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

After the Interceptor (interceptor N) returns the final response (httpservletresponse) of the executed (opposite to the execution of the action) to the Web. 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 J2EE features, 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. With a configuration file, you can grasp the relationship between all parts of the system, which is of great benefit for later maintenance. This advantage is especially evident when another 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 that encapsulates JDBC objects in a lightweight manner, so that Java programmers can use the object programming thinking to manipulate the database as they wish. Hibernate can be used in any situation where JDBC is used. It can be used in Java client programs or Servlet/JSP web applications. The most revolutionary is that, hibernate can replace CMP in the J2EE architecture of application EJB to fulfill the task of data persistence.

 

2. hibernate Core Components

 

Not specific

 

3. Basic hibernate Execution Process

 

 

Why hibernate?

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

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

3. Good portability and support for various databases. If you change a database, you only need to change the configuration in the configuration file. You do not need to change the hibernate code.

4. Transparent persistence is supported because hibernate operates purely (pojo) Java classes without implementing any interfaces and is not invasive. Therefore, it is a lightweight framework.

 

 

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

The SSH1 framework builds instances (spring2 + struts1 + hibernate3) using the old version. For details, see the comments in the code.

The latest version is used to build instances using the SSH2 framework (spring3.2 + strust2.3.4 + hibernate4.2). For details, see the comments in the code.

 

Build the development environment, refer to my other blog

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

 

 

 

[HTML]View plaincopyprint?
  1. Notes:
  2. I have sent all emails asking for code. If any emails are missed, contact me.
  3. I hope you can download it on the csdn download page. If the speed is slow, you can go here to http://pan.baidu.com/s/1eQh7FXo
  4. Development Environment configuration. Http://blog.csdn.net/shan9liang/article/details/8807784
  5. In war, locate the application-common.xml. Modify the data source and specify your own database. After the project is deployed, the table is automatically mapped.
  6. <! -- Configure the data source -->
  7. <Bean id = "datasource" class = "org. Apache. commons. DBCP. basicdatasource"
  8. Destroy-method = "close">
  9. <Property name = "driverclassname" value = "oracle. JDBC. Driver. oracledriver"/>
  10. <Property name = "url" value = "JDBC: oracle: thin :@ localhost: 1521: orcl"/>
  11. <Property name = "username" value = "ssh"/>
  12. <Property name = "password" value = "ssh"/>
  13. </Bean>
  14. The above is the configuration of oracle.
  15. If you use other databases, add the driver package to the lib directory. And modify the data source.
  16. It is strongly recommended that:
  17. Https://code.csdn.net/shan9liang/tgb
  18. This is a Attendance Management System hosted in csdn code and built using SSH. The Maven project is more standardized than the original one. We recommend using this system and I will continue to update it, gradually join various mainstream frameworks, believe me.
  19. . But it is not an Eclipse project. You need to manually import eclipse. intellij is a favorite recently. Git clone is recommended.

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.