In eclipse, learn about the SSH framework and simply write the following basic project operations and tips:
1. Guide package (the first step after creating the project, import all the relevant resource bundles into the project webcontent/web-inf/lib/), and find the resources that may be used, such as:
Struts-2.3.30.
Spring-4.2.2
Hibernate-5.2.2
(These are the resources used in this example)
Create a new project (click File-->new-->dynamic Web Project):
1.1, in the Srtuts-2 required in the jar package, decompression, and then copied to the project (webcontent \ Web-inf \ lib):
(Download it online, and then locate the appropriate folder that contains the resource bundle that you want, and then copy it into the project.) )
1.2. The jar package needed in spring:
(* Import the relevant resource bundle as needed, and the jar package can be removed from it.) *)
1.3. Jar packages needed in Hibernate:
There is also a package for the database pool, and if you use C3P0, you need to import the package (or use the corresponding database package).
2, the operation of the configuration file:
2.1. Web. XML configuration file
When you write the configuration file, you need to include both the STRUTS2 (filter) and the Spring (listener) sections.
The first is the processing of the head information (to choose the respective version);
Like what:
Above detailed content:
<web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xmlns= "Http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
Id= "webapp_id" version= "3.1" >
(The following two configurations are written in Web. xml)
The following are the configurations of the Struts filter:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Configuration of the Spring listener
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.2. Struts.xml configuration file
Part of the head information
Need to write on:
(This is a combination of the configuration files for spring and Struts2)
2.3. Inheritance and configuration of action class
Generally, the action class inherits Actionsupport:
Followed by a method (default to execute);
The following is the configuration information for the action:
2.4. Application.xml configuration file (and the "Bean" section), sessionfactory configuration file,
2.4.1, application.xml configuration file
The following information (placed in the header) is included in the Application.xml configuration:
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:p= "http://www.springframework.org/schema/p"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xmlns:context= "Http://www.springframework.org/schema/context"
Xmlns:jee= "Http://www.springframework.org/schema/jee"
xmlns:tx= "Http://www.springframework.org/schema/tx"
Xsi:schemalocation= "
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">
Then the <bean> section reads as follows:
Sessionfactory configuration file (which injects information such as connection pooling, databases, and hibernate to configure properties):
Where c3p0 is used, its configuration file is:
3. Briefly describe the connection of the database in SSH
The database connection path and password are listed in the following format, for example:
According to the above information, in the code can be written as:
In the SSH framework, the configuration file for database information needs to be added in Applicationcontext.xml:
(Thus, an external property file is introduced)
Above, is a simple example, the construction of the SSH framework and configuration files, in this basis can go to write programs, thus enriching the implementation of content, for reference.
Simple construction of SSH framework and configuration files