Build an ssh framework

Source: Internet
Author: User

Build an ssh framework

SSH is an integrated framework of struts + spring + hibernate. It is a popular open source framework for 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, to help developers build Web applications with clear structures, good reusability, and convenient maintenance in a short period of time. Struts is used as the overall infrastructure of the system and is responsible for the separation of MVC. In the model section of the Struts framework, business redirection is controlled, and the persistence layer is supported by the Hibernate framework. Spring is used for management, manage struts and hibernate. The specific method is to use the Object-Oriented Analysis Method to propose some models as needed, implement these models as basic Java Objects, and then compile the basic DAO (Data Access Objects) interface, the DAO implementation of Hibernate is provided. DAO classes implemented by the Hibernate architecture are used to implement conversion and access between Java classes and databases. Spring manages struts and hibernate.

Version used: running environment of Struts2 + Spring4 + Hibernate5: JDK1.8, Tomcat v8.0, eclipse4.6.0

Step 1: create a web project and add struts2

1. Remember to check an option when creating a web project.

  

  2. Add the jar package required by struts2

Download files from the official website (http://struts.apache.org)Struts-2.3.30-all.zip-- Unzip and open -->AppsDirectory -->Struts2-blank.war-- Unzip and open -->WEB-INFDirectory -->LibAllJarPackage

3. Configure the web. xml file and add the struts filter.

  

Step 2. Subcontracting

1. create four packages in the src folder of the newly created web project's Java Resources:

Ssh. entity package

Ssh. dao data layer package

Ssh. service layer package

Ssh. action web layer package

Below:

    

   2. Compile the action class

Create a class to inherit ActionActionSupport class, and create a constructor with the String type, return different return values according to the business logic, at the same timeStrutsDifferent return values are received to jump to different pages.

3. Compile the jsp display page

Compile one or more jsp pages to display the processed information. Different jsp pages are displayed based on different services.

4. Add the struts. xml file and configure

    What is the role of struts. xml? A:Struts. xml is used to associate the action class with the jsp page. That is to say, the data in the action class is processed and then transmitted to the jsp page for display.

InCreate a file named struts. xml under the src directory in Java Resources of the web project and configure the file as follows:

          

Step 3: Add spring and configure spring (spring monitors the program running at all times, injects instances during the program running, and manages all implementation classes)

1. Import package

Import the corresponding jar package (in the official spring package, the lib directory contains the jar package with the resource and javadoc suffixes ):

    In addition to the core jar packages of the above spring, you also need to import commons-logging.jar and struts2-spring-plugin.jar (the package is in Struts2 ).

  2. Add the Listener to the configuration file web. xml

  

  3. Create and compile the applicationContext. xml file

  

 

Step 4: Add hibernate (an intermediary between the server and the database): responsible for adding, deleting, querying, and modifying databases.

1. Import package

Download the official package from the official website> decompress the package>LibDirectory>RequiredAllJarPackage andOptionalDirectoryC3p0AllJarPackage

The jar packages under the required directory and optional Directory are as follows:

Under the required directory:

  

 

   In the c3p0 directory:

 

   

 

    [Note: If you want to use another connection pool, export the corresponding jar package]

    2. Write a ing file (name rule: JavaBeanName. hbn. xml must be consistent with the object class name)

    

    3. Write the applicationContext. xml file again (write the information in the hibernate. cfg. xml file)

    

    

      

    The above is my personal summary of the SSH framework. The language level is not high. If you do not understand it, please forgive me "!" "

 

 

 

 

 

 

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.