刚学SSH,现在来谈谈SSH的集成
首先是jar的导入,无可置疑要把SSH的jar包导入到lib下,还有数据库驱动包
接下来就是拷配置文件了,
1.修改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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.hibernate.cfg.xml
这个没什么好说的,配好就行了
3.Spring配置文件applicationContext-commons.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: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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.ret.dao.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>
这样hibernate就算集成好了,接下来是struts
4.web.xml
<package name="user" namespace="/" extends="struts-default" >
<action name="login" class="login" method="addUser">
<result>
<param name="success">/login.jsp</param>
<param name="error">/index.jsp</param>
</result>
</action>
</package>
5.applicationContext-actions.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: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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean name="login" class="com.ret.actions.UserAction" scope="prototype">
<property name="userDao" ref="userDao"/>
</bean>
</beans>
6.applicationContext-beans.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: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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="userDao" class="com.ret.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
这样,三大框架就算集成完成了
初学,还望大家不吝赐教
分享到:
相关推荐
struts spring hibernate ssh 三大框架集成详细步骤 手把手教你搭框架 步骤清晰;搭配MyEclipse 5.5 M2截图;让你不需要任何其他资料;跟着步骤;轻松搭建;
Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2Struts 2+Spring 3+Hibernate框架技术精讲与整合案例2
在MyEclipse中实现Struts2 Spring Hibernate三个框架的集成
介绍了Struts、spring、Hibernate三个框架集成开发的整个流程,介绍的非常详细。对于没有用过ssh框架进行过集成开发的人非常有用。
现在就将笔者使用Myeclipse工具应用struts2 + spring2 + hibernate3 实现CRUD操作的步骤一一纪录下来,为初学者少走弯路略尽绵薄之力!在本文中,笔者将Struts2.0.6、Spring2.0.6和Hibernate3.1进行整合,希望通过...
1、 同时使用了Struts2、Spring4、Hibernate4、Quartz、JUnit4、Log4j、SLF4J、Ehcache、Gson等库或框架,搭建一个最基本的项目原型。 2、 Spring配置提供了多种可选整合方案:详见applicationContext.xml的配置 (1...
本人自己动手集成的struts+spring+hibernate 网站后台管理系统,希望对刚学习struts的朋友带来一定的帮助,这是我上传此文件的最大愿望,里面有三个框架所需要的jar包和所有的配置文件,只要下载即可运行,不需要...
Struts2+Spring2+Hibernate3 web 应用示例,Struts2+Spring2+Hibernate3三个框架的集成说明,学习SSH2项目开发很有用
第三章 与Struts2、Spring集成 - 17 - 3.1. 业务逻辑层接口及实现类 - 17 - 3.2. Struts2的Action调用业务逻辑 - 19 - 3.2.1. 登录Action--OpenIDLoginAction - 19 - 3.2.2. 进入的Action—FirstPageAction - 20 - ...
自己做的一个小例子,有登录、查询和操作数据、、希望可以帮到大家!
130222.rar文件是一个精心打包的计算机专业JSP源码资料包,它集成了当前流行的Web开发框架:Struts, Spring, Hibernate以及Oracle数据库。此项目资料包为开发者提供了一个全面的、可立即部署的开发环境,旨在帮助...
Struts2与Spring、Hibernate的集成(S2SH+Mysql)一个很简单的实例,非常适合学习三大框架的的初学者学习。
ssh struts+hibernate+Spring 三个框架集成
如何在myeclipse中配置对三个框架的集成Spring\Hibernate\Struts
这是我自己做的练习,包括这三个框架集成,文件上传,下载,输入校验, 验证,里面还包括所需的全部jar包
Struts2、spring 、hibernate三个框架的整合
在这个资料包中,用户将会找到一个基于这三个框架的图书管理系统的完整源代码,包括了前端页面、控制器、业务逻辑层、数据访问层以及配置文件等。通过阅读和分析这些源码,用户可以学习到如何使用Struts处理用户请求...
SSH框架是一个由Struts、Spring和Hibernate三个开源框架组成的集成框架。 这个框架主要用于构建灵活、易于扩展的多层Web应用程序。SSH框架包含表示层、业务逻辑层、数据持久层和域模块层,它帮助开发人员在短期内...
Struts,Hibernate,Spring集成开发宝典(PDF格式),一本非常好的学习Java框架的书。由于比较大,所以压 缩成了五个部分,这是第三部分!
struts+hibernate+spring+blob 三个框架集成了一下,主要包括利用struts的上传附件功能,并把上传的图片存储到oracle的blob字段。并提供显示。 没做过多的限制,还有很多bug别见怪,功能跑得通!