Spring2.5 + Struts2 + Hibernate3 整合
Struts2,Spring2.5,Hibernate3整合
1. 在/WEB-INF/lib目录下放入已下jar包:
commons-logging-1.0.4.jar
freemarker-2.3.15.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
commons-fileupload-1.2.1.jar
struts2-convention-plugin-2.1.8.1.jar
struts2-spring-plugin-2.1.8.1.jar
spring.jar
commons-dbcp.jar
commons-pool.jar
hibernate3.jar
dom4j-1.6.1.jar
slf4j-log4j12-1.5.0.jar
slf4j-api-1.5.0.jar
log4j-1.2.15.jar
|
2. 配置/WEB-INF/web.xml文件:
<!-- Struts2配置 -->
<filter>
<filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring2.5配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
|
*至此,Struts2与Spring2.5已经整合完毕,但要看到效果和使用整合框架,需要继续以下步骤。
3. 创建Struts2和Spring2.5的配置文件
1. 在/WEB-INF/classes目录下建struts.xml文件(与web.xml中配置的文件名相同):
web.xml中的配置项为:
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
</init-param>
|
文件内容如下:
<?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>
<!-- 注意namespace为"/"表应用根目录,extends为"struts-default"不要写成"struts-defaults" -->
<package name="default" namespace="/" extends="struts-default">
<!-- action正常配置,只是将class配置成spring配置文件中的bean的id -->
<action name="example" class="spring.example">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
|
2. 在/WEB-INF/classes目录下建spring.xml文件(与web.xml中配置的文件名相同):
web.xml中的配置项为:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
|
文件内容如下:
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop=http://www.springframework.org/schema/aop
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 以下id值与struts配置文件中的class值对应 -->
<bean id="spring.example" class="com.erison.action.Example"/>
</beans>
|
4. 创建类及测试
建如下类com.erison.action.Example:
package com.erison.action;
public class Example {
public String execute() throws Exception {
return "success";
}
}
|
应用根目录下建如下文件index.jsp,bogy部分如下:
<body>
<h1>struts spring integraded! </h1>
</body>
|
部署应用到tomcat5.5或其它容器。
打开浏览器,在地址栏输入:http://localhost:8080/ssh/example.action,结果如下:
*至此,struts2和spring2.5的整合使用已经完成,以下整合Hibernate3。
下一篇 Spring2.5 + Struts2 + Hibernate3 整合 [2/2]
分享到:
相关推荐
struts2+spring2.5+hibernate3.2整合完整项目,带数据库脚本 ,mysql,tomcat,myeclipse完整工程
Spring2.5+Hibernate3.3+Struts1.3整合需要用到的所有jar文件
Spring2.5+Struts1.3.8+Hibernate3.0整合详细配置 希望对初学者有所帮助
这是一个spring2.5+struts2+hibernate3.3的整合完整项目,struts2的ActionBean,hibernate的sessionFactory交与了spring容器创建与管理
struts2.0+spring2.5+hibernate3.0整合框架,下载导入到eclipse下即可。。启动tomcat前先修改jdbc.properties文件。由于lib文件较大,所以请自行导入相关lib包。
NULL 博文链接:https://ilyon.iteye.com/blog/725910
这是一个完整的Spring2.5+Struts2.3+hibernate3.6整合实现登陆的实例,使用的数据库是Mysql,大家下下来还需要导入servlet-api.jar。
jbpm4整合struts2+spring2.5+hibernate3.3.doc
整合S2SH+Freemarker,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
Struts2+Spring2.5+hibernate3.3整合 Struts2+Spring2.5+hibernate3.3整合
利用ssh(Spring2.5+Struts2.1+Hibernate3.3)全注解整合这3个流行的框架,实现了增、删、改、查,分页,的功能。
struts2+spring2.5+hibernate3.2 找了半天没看到。自己整了一个。
Eclipse中Struts2+Spring2.5+Hibernate3整合,由于包超过上传限制,所以把lib里面的包给分成两个下载点,等下附上
整合S2SH+Freemarker+oscache,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
struts2+spring2.5+hibernate3整合经典实例 开发环境: MyEclispe 5.1 数据库:mysql5
SSH整合jar包-spring5.0+hibernate5.1+struts2.5 使用测试通过的
Dwr2+Struts2+Spring2.5+Hibernate3完美整合--用户登录注册系统
NULL 博文链接:https://gaobo424.iteye.com/blog/870162
struts2+spring2.5+hibernate3整合的完整示例,数据库为Oracle Database 10g Express Edition
以Struts2+Spring2.5+Hibernate3开发的网上购物系统,文件里面有数据库Oracle 10g,导入即可使用