SSH Framework Summary (frame Analysis + Environment Building + instance source download)

Source: Internet
Author: User

First, SSH is not a framework, but an integration of multiple frameworks (struts+spring+hibernate), which is now a popular open-source integration framework for Web applications to build flexible, easy-to-scale, multi-tiered Web applications.

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 business model components and the component's collaboration Object data Processing (DAO) components to the action to complete the business logic and to provide container components such as transaction processing, buffer pooling 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, forwarding the view according to the configuration file that describes the struts-config.xml of the model, view, and controller correspondence ( View), 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

1234567891011121314151617181920212223242526272829303132 一些说明:索要代码的邮箱,我基本上都发过了,如果有漏发,请联系我。还是希望大家去csdn下载页去下载。如果速度慢,可以去这里http://pan.baidu.com/s/1eQh7FXo 开发环境配置。http://blog.csdn.net/shan9liang/article/details/8807784  在war中,找到application-common.xml。修改数据源,指定自己的数据库即可。项目部署后,会自动映射表。    <!--配数据源 --><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>  以上是oracle的配置。如果使用其他数据库,请在lib目录下,加入驱动包。并修改数据源。强烈建议:https://code.csdn.net/shan9liang/tgb这是在CSDN CODE托管的,采用ssh搭建的一个考勤管理系统,maven项目,比原来那个更规范了,建议用这个,而且我会持续更新,逐渐加入各种主流框架,相信我。。不过不是eclipse项目,需要手工导入eclipse,最近特喜欢用intellij。建议直接用git clone。
QQ Group: Web Developer Official Group (321386971) authentication message: Admin10000

SSH Framework Summary (frame Analysis + Environment Building + instance source download)

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.