Integrate the detailed configuration steps and precautions of struts2 + hibernate, struts2hibernate

Source: Internet
Author: User

Integrate the detailed configuration steps and precautions of struts2 + hibernate, struts2hibernate

After learning these two frameworks, I can't wait to make an example. When integrating the two frameworks, I also encountered some minor problems. The following describes the configuration steps:

1. Create a custom struts2 and hibernate class library

Because the previous examples are to directly drag the jar package to the lib package under the WEB-INF, but here you need to import the jar packages of the two frameworks, put together, it will be messy, therefore, it is best to create a custom Class Library:

1. window-> Preferecces-> Java-> BuildPath-> UserLibraries-> new.

      

Take the struts2 class library as an example, enter the struts2-core, click OK. Select the file, click Add External JARs..., find the core jar package of struts2, all put in. Click OK after completion.

      

Hibernate jar package, steps are the same as above.

2. Import the jar packages of struts and hibernate.

Create a Web project, right-click the current project, and choose Propertie> Java buildPath> Libraries> Add Libraries> User Libraries.

Find the previously created class library and import it.

 

3. Configure web. xml.

Add the core filter of struts2 to web. xml:

  <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>
4. Create struts. xml.
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"    "http://struts.apache.org/dtds/struts-2.3.dtd"><struts>    <package name="default" namespace="/" extends="struts-default">    

</package></struts>
5. Create and configure hibernate. cfg. xml in the src directory:
<! DOCTYPE hibernate-configuration PUBLIC "-// Hibernate/Hibernate Configuration DTD 3.0 // EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

Now that the environment has been configured, you can enjoy the convenience brought by the Framework :)

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.