First, SSH is not a frame, but multiple frames ( struts+spring+hibernate ) is integrated is one of the more popular open source Web applications right now. Integrated Framework for building flexible, easy-to-scale, multi-tiered Web applications .
the system of integrated SSH framework is divided into four layers: presentation layer, business logic layer, data persistence layer and Domain module layer. (entity layer).
Struts as a system of The overall infrastructure, which is responsible for the separation of MVC, controls the business jump in the model section of the Struts framework, and supports 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, and one aspect to enable Struts and Hibernate to work better.
by SSH Build the basic business process of the system is:
1 , in the presentation layer, the interface is first implemented via a JSP page, which is responsible for transmitting requests and receiving responses (Response), and then struts according to the configuration file (Struts-config.xml) Delegate the request received by Actionservlet to the corresponding action handle.
2 , in the business layer, the spring IOC container that manages the serviced component is responsible for delivering 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 transactional 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 results.
The above development model not only realizes the 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 only needs very little modification, 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 for team members to work in parallel, which greatly improves the development efficiency.
Let's take a look at these 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
Detailed self Baidu bar
All of these features of spring allow you to write cleaner, more manageable, and easier-to-test code
3. Why use Spring?
The above features of spring allow developers to use the main JavaBean to complete things that were once only possible by EJBS. However, the use of spring is not limited to server-side development. From a simple, test-and loosely-coupled perspective, no Java application can benefit from spring.
Second, Struts
1. What is struts?
It implements the application framework of MVC design pattern based on Java EEWeb application by adopting Java Servlet/jsp Technology, 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 a controller, according to the configuration file describing the struts-config.xml of the corresponding relationship between the model, the view, the controller, and the forwarding view Request, assemble the response data model.
In the model section of the MVC, it is often divided into two major subsystems (the internal data state of the system and the logical action of changing the state of the data), the two conceptual subsystems in detail corresponding to the actionform in Struts 1 and the action two need to inherit the implementation superclass. 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 the standard JavaServer Pages (JSP), a large number of tag library uses are available and can be integrated with other presentation component technologies (products) at the same time, for example Velocity Templates, XSLT and so on.
By applying Struts's framework, users are finally able to place most of their focus on their business logic (Action) and the mapping relationship configuration file (Struts-config.xml).
3, the basic operating 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 handle the user's request, and this design also allows the business logic controller to completely disengage from SERVLETAPI, so struts 2 can be understood as WebWork's new product
5. STRUT2 Architecture
Analytical:
When the Web container receives the request (HttpServletRequest) It passes the request to a standard filter chain containing 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 action-specific information.
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 string is returned actioninvocation is responsible for finding the result string corresponding (result) and then running this result result will call some templates (JSP)
To render the page, and then the Interceptor (Interceptor N) responds to the last response (HttpServletResponse) when it is run (opposite to the action run) 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 whole system of the connection between the parts, which for the later maintenance has great advantages. This is especially true when there is a group of developers taking over the project.
7. Differences 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 a lightweight object encapsulation of JDBC, allowing the Java program ape to manipulate the database at will using object programming thinking. Hibernate can be used wherever JDBC is used, both in Java client applications and in servlet/jsp Web applications, the most revolutionary of all Hibernate can replace CMP in the application of EJB's Java EE Architecture and complete the task of data persistence
2.Hibernate Core composition
The details will not unfold
3.Hibernate basic Operation Process
Why use Hibernate?
1. The code for the JDBC Access database is encapsulated, which greatly simplifies the tedious and repetitive code of the data interview layer.
2 , Hibernate is an excellent ORM implementation. He greatly simplifies the coding of the DAO layer, freeing the software developer from the extensive programming of the same data persistence layer and making the development more object-based.
3 , good portability, support a variety of databases, it is assumed that the replacement of a database only in the configuration file transformation configuration can be, do not change hibernate code.
4 , supports transparent persistence, because Hibernate operates purely (Pojo) Java classes, no interface is implemented, no intrusion. So it's a lightweight framework.
Finally attach the example of SSH1 and SSH2 frame, click to download
SSH1 Frame Construction Example (spring2+struts1+hibernate3) use the old version number, see the code in the gaze
SSH2 Frame Construction Example (spring3.2+strust2.3.4+hibernate4.2) all the latest version numbers, see the code for the gaze
Development environment Construction, and I have a blog
"Win7" + Eclipse (+ tomcat7) + JDK7 (64) Development environment Configuration
Some instructions: Ask for the code of the mailbox, I have basically sent, if there is a leak, please contact me. Or you want to go to the csdn download page to download. Assuming the speed is slow, be able to go here http://pan.baidu.com/s/1eQh7FXo development environment configuration. http://blog.csdn.net/shan9liang/article/details/8807784 in the war, find Application-common.xml. Change the data source to specify your own database. After the project is deployed, the table is actively mapped on its own. <!--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> above is the configuration of Oracle. If you use a different database, under the Lib folder, add the driver package. and change the data source. Highly recommended: Https://code.csdn.net/shan9liang/tgb This is managed in CSDN code, using SSH to build an attendance management system, MAVEN project, more than the original one, recommend this, and I will continue to update, Gradually add a variety of mainstream frameworks, believe me. Just not eclipse project, need to manually import eclipse, recently special like to use IntelliJ. It is recommended to use Git clone directly.
SSH Framework Summary (frame Analysis + Environment Build + instance source code download)