Struts2+Spring+Hibernate(SSH)框架的搭建
首先需要下载struts2 ,spring4,hibernate5 的资源包;
struts2资源包下载路径:http://www.apache.org/
spring资源包下载路径:http://projects.spring.io/spring-framework/
hibernate资源包下载路径:http://hibernate.org/orm/downloads/
在SSH框架的搭建步骤:
第一步:在eclipse中创建一个web项目,并生成web.xml文件;
第二步:往lib目录导入jar包:
1.struts2所需的jar包:
struts2.3.30\apps\struts2-blank\WebContent\WEB-INF\lib(如图所示:)

2.spring 所需的jar包:
spring-framework-4.2.2.RELEASE-dist\spring-framework-4.2.2.RELEASE\libs(如图所示:)

3.hibernate所需的jar包:
hibernate-release-5.2.2.Final\lib\required(如图所示:)

4.mysql数据库以及dbcp连接池所需的jar包:(如图所示:)

第三步:在web.xml 文件中配置struts的过滤器 ,spring 的监听器;(代码如下:)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>ssh</display-name>
<welcome-file-list>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!--配置struts的过滤器 -->
<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> <!--配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
第四步:在src目录下创建四个包,分别是action 控制层、dao 数据层、entity 实体层 ,
service 业务层;(如图所示:)

第五步:struts.xml的配置:在src目录下创建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> <!-- 第1步:先定义一个包 -->
<package name="mypck001" extends="struts-default"> <action name="Index" class="myIndexAction" method="execute1">
<result name="success">/WEB-INF/jsp/index2.jsp</result>
<result name="error">/WEB-INF/jsp/s_tag.jsp</result>
</action>
</package>
</struts>
第六步:spring的配置与hibernate的配置: 在src目录下创建applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
<!-- 引入外部属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/> <!-- 所有需要类的实例都由spring去管理 -->
<bean id="myIndexAction" class="ssh.action.IndexAction" scope="prototype">
<!-- setIs(myIndexService) -->
<property name="is" ref="myIndexService"/>
</bean> <!-- myIndexService = new ssh.service.IndexServiceImpl() -->
<bean id="myIndexService" class="ssh.service.IndexServiceImpl" scope="prototype">
<property name="id" ref="myIndexDao"/>
</bean> <bean id="myIndexDao" class="ssh.dao.IndexDaoImpl" scope="prototype">
<!-- 注入seesionFactory -->
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean> <bean id="mySessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 注入连接池,包含了数据库用户名,密码等等信息 -->
<property name="dataSource" ref="myDataSource"/> <!-- 配置Hibernate的其他的属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<!-- 开机自动生成表 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property> <property name="mappingResources">
<list>
<value>ssh/entity/BookCard.hbm.xml</value>
</list>
</property> </bean>
<!--c3p0连接池-->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 每300秒检查所有连接池中的空闲连接 -->
<property name="idleConnectionTestPeriod" value="300"></property>
<!-- 最大空闲时间,900秒内未使用则连接被丢弃。若为0则永不丢弃 -->
<property name="maxIdleTime" value="900"></property>
<!-- 最大连接数 -->
<property name="maxPoolSize" value="2"></property> </bean> <!-- dbcp连接池 -->
<!--切换dbcp连接池 要导入commons-dbcp.jar 和 commons-pool.jar 包 -->
<bean id="myDataSource2" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>
Struts2+Spring+Hibernate(SSH)框架的搭建的更多相关文章
- struts2+spring+hibernate(SSH)框架的搭建和总结
SSH框架:struts2+spring+hibernate,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. struts2+spring+hibernat ...
- Struts2+Spring+Hibernate 三大框架的合并集成
这次来看看Struts2+Spring+Hibernate三大框架的整合应用,主要是Spring和Hibernate框架的整合,因为前边已经将Strtus2+Spring整合过了基本一样. 首先看一 ...
- Eclipse搭建SSH(Struts2+Spring+Hibernate)框架教程
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 确实,刚创博客,对于这个陌生的东西还是有些许淡然.这是我的第一篇博文,希望能给你们有帮助,这就是我最大的乐趣! 好了下面进入正题: SS ...
- Struts2,Spring,Hibernate三大框架的整合(SSH)
一.搭建struts2 1).导入struts2 jar包 2).编写web.xml 3).编写jsp页面 4).创建action类,action类要继承ActionSupport类 5).创建str ...
- java 的 struts2 Spring Hibernate 三大框架的整合
原理就不说了,直接上配置文件及代码,用来备用 首先,将三大框架所需要的jar包导入项目中 导入 struts2-spring-plugin-2.3.3.jar包 此包的作用是作为struts2 与 ...
- SSH(Struts2+Spring+Hibernate)框架搭建流程<注解的方式创建Bean>
此篇讲的是MyEclipse9工具提供的支持搭建自加包有代码也是相同:用户登录与注册的例子,表字段只有name,password. SSH,xml方式搭建文章链接地址:http://www.cnblo ...
- SSH框架简化(struts2+spring+hibernate)
目的: 通过对ssh框架有了基础性的学习,本文主要是使用注解的方式来简化ssh框架的代码编写. 注意事项: 1.运行环境:Windows 8-64位,Eclipse(开发工具),jdk1.8.0_91 ...
- 基于Maven的S2SH(Struts2+Spring+Hibernate)框架搭建
1. 前言 基于Maven的开发方式开发项目已经成为主流.Maven能很好的对项目的层次及依赖关系进行管理.方便的解决大型项目中复杂的依赖关系.S2SH(Struts2+Spring+Hibernat ...
- Maven搭建struts2+spring+hibernate环境
Maven搭建struts2+spring+hibernate环境(一) 本文简单的使用STS的自带的maven插件工具搭建ssh(struts2+spring+hibernate)开发环境,图文并茂 ...
随机推荐
- Flash Builder 调试器无法连接到正在运行的应用程序(57%)
Flash Builder 调试器无法连接到正在运行的应用程序(57%),可能原因: 1,flashplayer不是debug版. 2,调试器(用debug版flashplayer随便 ...
- ArcMap中地图输出(Options)选项显示不完整
首先,我开始遇到的时候,认为是高分辨屏幕的问题,所以修改了屏幕的分辨率,结果并没有改变. 然后,认为是对话窗口的显示,修改字体大小,也没有显示完整. 最后,是修改了ArcGIS的注册表才解决.解决方式 ...
- EXCEL拼接SQL
=CONCATENATE("insert into 表名 (字段名1,字段名2)values (3, '"&C3&"');") 用CONCAT ...
- Coursera Machine Learning 作业答案脚本 分享在github上
Github地址:https://github.com/edward0130/Coursera-ML
- JavaWeb 学习005-4个页面,5条sql语句(添加、查看、修改、删除)
今天完成了的事: = 1.班级模块,list页面的添加班级信息操作,中文乱码问题 尚待解决 这俩天做得工作是: 首先搭建好main页面:是由top.left.right三个部分构成的,拼接到一起. 流 ...
- 合并两个排好序的链表(c++)
#include<iostream> struct node{ int payload; node* next; node(int payload){this->payload=pa ...
- $.each与$().each
在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法.两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点. $().each,对于这个方法,在d ...
- 使用spring-data-solr做solr客户端
solr的客户端基本上只有一个,那就是solrj,spring-data-solr是在solrj的基础上做的封装,使统一成spring-data的风格 官方网站: http://projects.sp ...
- transition-delay
https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay
- pll及其modesim仿真
100mhz输入时钟,pll层40mhz和200zhm 进入quartus,建立工程,新建图形文件,导入pll模块,设定pll相关参数. 完成pll模块的建立,并生成pll.v文件 建立modes ...