First, SSH is not a framework, but an integration of multiple frameworks (Struts+spring+hibernate), a more popular web application open Source Integration Framework for building flexible, scalable, multi-tier 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 the overall infrastructure of the system, responsible for the separation of MVC, in the struts framework of the Model section, control business jumps, using the Hibernate framework to support the persistence layer. As a lightweight IOC container, spring is responsible for finding, locating, creating, and managing dependencies between objects and objects, and on the other, enabling struts and hibernate to work better.
The basic business process for building a system from SSH is:
1, in the presentation layer, first through the JSP page to implement an interactive interface, responsible for the transfer 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 processing.
2. In the business layer, the spring IOC container that manages the service components is responsible for providing the action with the business model component and the component's collaboration Object data Processing (DAO) component to complete the business logic and providing container components such as transaction processing, buffer pooling to enhance system performance and ensure data integrity.
3, in the persistence layer, depends on the hibernate 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 view, controller and model, but also realizes the separation between the business logic layer and the persistence layer. So no matter how the front end changes, the model layer needs little changes, and the database changes will not affect the front-end, greatly improve the system reusability. Because of the small coupling between different layers, it is helpful for team members to work in parallel and improve the development efficiency greatly.
Now let's look at the three frames that make up ssh
First, Spring
1, what is spring.
In short, spring is a lightweight control reversal (IoC) and aspect-oriented (AOP) container framework.
2. Spring Features
The specific own Baidu bar
All of Spring's features enable you to write cleaner, more manageable, and easier to test code
3. Why spring is used.
The above features of spring enable developers to use basic javabean to accomplish things that were previously only possible by EJB. However, the purpose of spring is not limited to server-side development. In terms of simplicity, testability, and loose coupling, any Java application can benefit from spring.
Second, Struts
1, what is struts.
By adopting Java servlet/jsp Technology, the application framework of MVC design pattern based on Java eeweb application is realized, which is a classic product in MVC Classic design pattern.
2, the core composition of Struts1
In Struts1, a Servlet called Actionservlet acts as the controller (Controller), forwarding views according to the Struts-config.xml configuration file that describes the model, view, and controller corresponding relationship (view) The request to assemble the response data models (model).
In the MVC model section, it is often divided into two main subsystems (the system's internal data state and the logic action to change the state of the data), and the two conceptual subsystems correspond specifically to the Actionform and action two in Struts 1 to implement the 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 using standard JavaServer Pages (JSP), a large number of tag libraries are available and can be integrated with other performance Layer component technologies (products), such as Velocity templates,xslt Wait
By applying Struts's framework, end users can place most of their concerns in their own business logic (Action) and Mapping relationship profiles (Struts-config.xml).
3, Struts1 the basic implementation process
See the basic work flow of struts
4, what is Struts2
Struts 2 is the next generation of struts, a new Struts 2 framework that has been merged on the basis of Struts 1 and webwork technology. Its new Struts 2 architecture differs enormously from the Struts 1 architecture. Struts 2 takes the webwork as the core, uses the interceptor mechanism to handle the user's request, such design also enables the business logic controller to be able to completely disengage with the SERVLETAPI, therefore struts 2 can understand as webwork the new product
5, the 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, 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 return a Actionmaping object that collects action details.
Next Filterdispatcher delegate control to the Actionproxy,actionproxy call Configuration Manager (ConfigurationManager) to read the configuration information (Struts.xml) from the configuration file. The Actioninvocation object is then created, actioninvocation the configured interceptor (Interceptor N) to be invoked in turn before the action is invoked Once the result is returned the result string actioninvocation is responsible for finding the resulting string corresponding to (result) and then executing the results will invoke some templates (JSP)
To render the page, after which the Interceptor (Interceptor N) is finally responded to (in reverse) (before the Order and action is performed) (HttpServletResponse) Those filters and (core controllers) (Filterdispatcher) that are returned in the Web.xml configuration.
6, why use struts.
First, Struts is an implementation of MVC, which uses the servlet and JSP tags (which belong to the Java EE Specification) as part of the implementation. Struts inherits the features of MVC and makes corresponding changes and extensions based on the features of Java EE, weakening the coupling between business logic interfaces and data interfaces, and making the view layer more varied
In addition, struts has the page navigation function, causes the system the vein to be clearer. Through a configuration file, you can grasp the whole system of the relationship between the parts, which for the maintenance of the latter has great benefits. This is especially true when another group of developers takes over the project.
7, the difference between Struts1 and Struts2
See "Struts1 and Struts2" for details.
Third, Hibernate
1, what is hibernate.
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, The task of completing data persistence
2, Hibernate core composition
It's not going to start.
3, Hibernate basic implementation process
Why use Hibernate.
1. The code for JDBC access to the database has been encapsulated, simplifying the cumbersome 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 a large number of the same data persistence layer programming work, so that the development of more object-oriented.
3, good portability, support a variety of databases, if you change the database as long as the configuration file in the transformation of the configuration can be, do not change the hibernate code.
4, support transparent persistence, because hibernate operation is pure (Pojo) Java class, do not implement any interface, no intrusion. So, it's a lightweight framework.
finally attach the SSH1 and SSH2 frame to build the example, click can download
SSH1 Frame Building Example (spring2+struts1+hibernate3) using the old version, see code comments
SSH2 Frame Construction Example (spring3.2+strust2.3.4+hibernate4.2) All adopt the latest version, see Code comments
development Environment, refer to my other blog
"Win7 + Eclipse" + TOMCAT7 (+) + JDK7 (64) Development environment Configuration
[HTML] view plain copy print? Some instructions: request the code of the mailbox, I basically have been sent, if there is a leak, please contact me. Still want everyone to go to the csdn download page to download. If the speed is slow, you can 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. Modify the data source and specify your own database. When the project is deployed, the table is automatically mapped. <!--with data source--> <bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" & Gt <