Illustration: Configure STRUTS + hibernate + spring + freemarker in myeclipse

Source: Internet
Author: User
Over the past few days, I have made Hibernate and spring look good. I think about some of struts's things and decided to integrate the three things. The presentation layer uses STRUTS + freemarker and the business layer uses spring, hibernate processes the persistent layer. In struts, authorization is used to delegate action processing to spring. Struts is only responsible for page logic.
A few days ago, eclipse 3.2 + myeclipse5.0m2 came into being. I felt that some of myeclipse's things were good and I would use it for integration.
First, create a web project:


Then, add some struts files to the newly created Project:


The project structure is as follows:

Add the file required by hibernate:






After completion, the project structure is:

Then add the spring file:

Note the following options:



After completion, you can see:

Open applicationcontext. xml and set

Changed:

Now, you still need to make some modifications to avoid errors during running. When I used to write STRUTS + hibernate, an error is thrown because of the xerces contained in hibernate. jar, so it is okay to delete it directly.

In spring and hibernate, there are two log4j. Jar files. The old version is not easy to use, so delete the file and change it to a new version.
Delete and replace with, and then add a log4j. properties under SRC:

The content is as follows:

In this way, log4j is configured.
The next step is to join freemarker, JSP is not comparable, personal feeling.
First, add freemarker. jar to the lib directory under the WEB-INF, and then open web. XML, add the following content:



Next we will discuss some practical exercises.
Switch to the hibernate view of myeclipse.

Open the database connection:


Then, execute


Automatically generate several files:

In addition, spring applicationcontext. XML is automatically added

Then, create the FTL page and set freemarker according to the preceding freemarker configuration in Web. xml. You need to create the following directory:

First, the page logic processing, open the struts-config.xml, and then perform the following operations



Continue to add




The effect is as follows:

The following are three pages:



Note the first two lines. Use the struts tag in freemarker.
As mentioned above, the action is delegated to spring and may be added to struts.

Then, the action class needs to be modified.

The following setter is prepared for spring.
Modify the Action Declaration for struts configuration. The proxy is used:

Add the following in spring applicationcontext. xml:

Note that name is used, not ID.
Publish, run, and an error is thrown in the result

Fortunately, the problem is not big, find to add to the WEB-INF/lib can be.
Start testing

Successful:

Otherwise:

Then I went to the database and checked it out. I was depressed and the data didn't come in. I tried it for a long time. Finally, I found that a datasource should be defined in spring. The original sessionfactory definition is as follows:

OK. Everything is normal. Now, I have finished writing it, just to illustrate how to use myeclipse for rapid development. After all, the project usually requires progress and quality supervision. With myeclipse, it is indeed quite convenient.

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.