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 :)