struts2+spring+hibernate(SSH)框架的搭建和总结
SSH框架:struts2+spring+hibernate,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活、易于扩展的多层Web应用程序。
struts2+spring+hibernate架包的下载地址:
struts2:http://struts.apache.org/ 因为这是国外网站,所以访问的时候会比较慢,请耐心等待
spring:这个官网现在已经不提供下载了,百度spring-framework-4.3.2.RELEASE,有人会封装好给你下载的
当然,我也是有准备的:spring-framework-4.3.2.RELEASE;
hibernate:https://sourceforge.net/projects/hibernate/files/latest/download?source=files 打开这个网址它就会自动下载
也可以这样下载:http://hibernate.org/orm/downloads/
具体怎么下载我就不一一细说了,下载完成后,我们找到文件目录。strut2的架包在lib目录的下面,spring的架包在libs目录下面,hibernate的架包在lib\required目录里。
准备好这些包之后,打开eclipse,新建一个项目如(图1).
(图1).

把包导入,当然不是所有的包都需要。struts2所需要的架包如图2.
(图2).
spring所需要的架包如图3.
(图3).
hibernate所需要的架包如图4.
(图4).
这些架包都是我们现在需要的,全部放入项目的lib中。
SSH框架集成从职责上分为4个层:表示层、业务逻辑层、数据持久层和实体层。
把JSP页面和包全部新建好。如图5.
(图5).

先把配置文件准备好,
struts2过滤器配置:
<?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>ZSSH</display-name>
<!-- 这是一只拦路虎 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<!-- filter的名字 -->
<filter-name>struts2</filter-name>
<!-- struts2所需要的驱动类 -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<!-- filter过滤的名字 -->
<filter-name>struts2</filter-name>
<!-- filter过滤的路径 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
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">
<!-- 上面的头,注意版本,从样例里复制过来 showcase.war\WEB-INF\src\java\struts.xml --> <struts> <!-- 第1步:先定义一个包 -->
<package name="mypck001" extends="struts-default">
<!-- 第2步:定义一个action,配置跳转信息 name 类似于Servlet @WebServlet("/IndexServlet")
http://xxxx/xxx/Index.action http://xxxx/xxx/Index class 对应于自己写的Action类 当不写method属性时,默认调用的是execute
class="ssh.action.IndexAction" ** new ssh.action.IndexAction()
设计思想:关心了具体的实现类
必须改为不要关注那个实现类
加入spring后,struts的action节点的class属性意义发生变化,
直接引用spring帮忙创建的实例
--> <action name="Index" class="myIndexAction" method="execute1">
<!--
跳转是forward
/WEB-INF/是防止jsp不经过action就可以访问
-->
<result name="success">/WEB-INF/jsp/index.jsp</result>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</action>
</package>
</struts>
struts001
<?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">
<!-- 上面的头,注意版本,从样例里复制过来 showcase.war\WEB-INF\src\java\struts.xml --> <struts>
<package name="mypck002" extends="struts-default"> </package>
</struts>
struts002
<?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">
<!-- 上面的头,注意版本,从样例里复制过来 showcase.war\WEB-INF\src\java\struts.xml --> <struts>
<!-- 第1步:先定义一个包 -->
<package name="mypck003" extends="struts-default"> </package>
</struts>
struts003
<?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">
<!-- 上面的头,注意版本,从样例里复制过来 showcase.war\WEB-INF\src\java\struts.xml --> <!-- include文件用于分割,实现多人并发不冲突 -->
<struts>
<!-- 告知Struts2运行时使用Spring来创建对象 -->
<constant name="struts.objectFactory" value="spring" />
<include file="s001.xml" />
<include file="s002.xml" />
<include file="s003.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_001</display-name>
<welcome-file-list>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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> <!-- 确定多个配置文件 -->
<context-param>
<!-- 参数名为contextConfigLocation -->
<param-name>contextConfigLocation</param-name>
<!-- 多个配置文件之间以,隔开二 -->
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<!-- 采用listener创建Applicat工onContext 实例-->
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
struts2+spring+hibernate(SSH)框架的搭建和总结的更多相关文章
- Struts2+Spring+Hibernate(SSH)框架的搭建
首先需要下载struts2 ,spring4,hibernate5 的资源包; struts2资源包下载路径:http://www.apache.org/spring资源包下载路径:http://p ...
- 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)开发环境,图文并茂 ...
随机推荐
- iOS开发之Runtime机制深入解析
本篇主要讲述在 OC 开发中主要涉及到的运行时机制: 运行时的工作: 运行时在 OC 中的工作:OC 语言的设计模式决定了尽可能的把程序从编译和链接时推迟到运行时.只要有可能,OC 总是使用动态的方式 ...
- Android 应用程序集成Google 登录及二次封装
谷歌登录API: https://developers.google.com/identity/sign-in/android/ 1.注册并且登录google网站 https://accounts. ...
- Macosx 安装 ionic 成功教程
一.首先介绍一下ionic ionic是一个用来开发混合手机应用的,开源的,免费的代码库.可以优化html.css和js的性能,构建高效的应用程序,而且还可以用于构建Sass和AngularJS的优化 ...
- 使用Project进行项目管理 - 项目管理系列文章
前面当项目经理的时候曾经用到过Project来进行项目管理.这些天闲着无事,将代码翻出来留念了一下,现在将Project项目管理的东西也翻出来玩玩. 微软的Project是一款不错的软件,经过微软这么 ...
- 专用服务器模式&共享服务器模式
连接ORACLE服务器一般有两种方式:专用服务器连接(dedicated server)和共享服务器连接(shared server).那么两者有啥区别和不同呢?下面我们将对这两者的区别与不同一一剖析 ...
- OpenGL ES无法获取贴图数据原因
最近在做一个项目,要从贴图中获取图像数据,查了很多资料,也琢磨很久,获取到的数据都是0.终于在一次偶然的机会,发现了端倪,成功了. 不得不说这"一分灵感"真的很重要 以下是在获取贴 ...
- HTML基本组成结构与标签的认识
HTML基本组成结构与标签 其实组成结构用一张图来简单了解下如下 目前一般网站的结构是会如此不是很清晰简单 先来说说header头部 这样是不是更加清楚了 导航栏是引导用户查看网站内容的快捷入口,打个 ...
- SQL SERVER 2014 各个版本支持的功能
转自:https://technet.microsoft.com/library/cc645993 转换箱规模限制 功能名称 Enterprise Business Intelligence Stan ...
- WinCE非通用调试工具汇总
WinCE-IIC调试助手(S3C2410) http://www.cnblogs.com/we-hjb/archive/2008/10/19/1314562.html WinCE下音频频谱显示(TD ...
- 【转载】Serif和Sans-serif字体的区别
在西方国家罗马字母阵营中,字体分为两大种类:Sans Serif和Serif,打字机体虽然也属于Sans Serif,但由于是等宽字体,所以另外独立出Monospace这一种类,例如在Web中,表示代 ...