struts 2.1.8 + spring 2.5.5 + hibernate 3.3.2整合實踐

第一步:建立好web工程

第二步:配置struts
把以下包放到lib文件夾
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
在web.xml添加filter

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

src目錄建立struts.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
</struts>

第三步:加入spring
把spring 2.5下的spring.jar和struts下的struts2-spring-plugin-2.1.8.1.jar放到lib
在web.xml加入一些內容

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

新建WEB-INF/application.xml

<?xml version="1.0" encoding="UTF-8"?>
<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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
</beans>

第四步:加入hibernate
把hibernate3.3下的hibernate.jar和lib\required下的所有jar都放到lib文件夾
加入commons-dbcp.jar,commons-pool.jar,mysql-connector-java-5.0.8-bin.jar
可能還需要slf4j-nop-1.5.2.jar
然後在application.xml加入datasource,sessionFactory其他元素,具體都可以在網絡搜索得到。

由於對struts瞭解不多,暫時還沒加入一些數據庫的操作。遲點再看看先! :)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章