SSH three-frame building integration (struts2+spring+hibernate) (Turn)

Source: Internet
Author: User

Original address: http://blog.csdn.net/kyle0349/article/details/51751913 respect for the original, please visit the original address

SSH is said to be Javaweb Classic framework, can not say 100% to SSH framework, but most of the companies are in use, speaking of the framework, will refer to SSH, this time with a very simple registration example to integrate the SSH framework. The integration framework should pay attention to the first after each frame alone after the integration, or the integration after the problem is more difficult to troubleshoot.
Environment: Windows + myeclipse + JDK1.7 + Tomcat7 + MySQL
The code has been measured, if there is an error may be I did not describe in some places, please leave a message.

This integration introduces the jar package, (not the simplest, some packages may not necessarily be used)

Filling the jar pack: http://download.csdn.net/detail/kyle0349/9559025

**

Struts2.3

**
1. Import Jar Package
2. Configure Web. xml

3. Create JS Page

4. Create an Action class

5. Configuring the Struts.xml File

Here Struts2 Configure the classes to test whether STRUTS2 is running correctly before and after you integrate spring. Then configure spring and consolidate struts2

Spring

1. Import Jar Package
2. Add spring Support (listener) to Web. xml

3. Add the Applicationcontext.xml file to the SRC directory to manage the creation of the Action object

Give the action's creation to spring management,
Spring Default scope is a singleton mode, which creates only one action object,
The action requires each access to create a new action, and scope= "prototype" ensures that a new action will be created each time a new visit is made. Ensure that each request has a separate action to handle, avoiding thread-safety issues with the action in struts.
4. Modify the class address of the action reference in Struts.xml, and instead create the ID of the Action object in spring, so that the action object is actually given to spring to create.

Comparison with the 5th step of the STRUTS2 configuration

Hibernate

1. Import Jar Package
2. Create an entity class

...
Get/set method
...
3. map file User.hbm.xml Create a mapping file under the same package, naming the format entity.hbm.xml

Configuration information

4, the creation of DAO layer, Service layer (basic additions and deletions for testing)

PS. Description: The DAO implementation class inherits the Hibernatedaosupport and can get the session directly without the need of sessionfactory.

5, the action layer in front of the configuration struts2 on the basis of the addition of business code (increase and deletion of check)

There are two ways to get a userservice:
Get/set Way
Annotation method
6, in the Applicationcontext.xml configuration file configuration integration information
A, (If you use the class annotation method, you need to turn on annotation scanning)

B. Create action object, UserService object, Userdao object

Ps. I userdao here is Get/set Way, Action,userservice is the annotation way
C, database connection (consolidated Spring-hibernate, I am the original Hibernate configuration file written to spring)
Do not need to build a database table, as long as the corresponding database can be guaranteed,



Ps. Database connection information is not written dead to the code, but with db.properties configuration and then pour, the advantage is to change the database at any time
Db.properties data

Hibernate is actually well-established and integrated into spring, and there is no separate test to test directly with the Web.

PS. If the consolidation sequence is hibernate–spring–struts2 will it be reasonable?

SSH three-frame building integration (struts2+spring+hibernate) (EXT)

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.