SSH:顾名思义(spring,struts2,hirbernate)

    Struts(表示层)+Spring(业务层)+Hibernate(持久层)

Struts是一个表示层框架,主要作用是界面展示,接收请求,分发请求。在MVC框架中,Struts属于VC层次,负责界面表现,负责MVC关系的分发。(View:沿用JSP,HTTP,Form,Tag,Resourse ;Controller:ActionServlet,struts-config.xml,Action) Hibernate: Hibernate是一个持久层框架,它只负责与关系数据库的操作。

Spring: Spring是一个业务层框架,是一个整合的框架,能够很好地黏合表示层与持久层。


前提条件:(引入三大框架的jar包)

第一步:搭建分层(以购买股票为案例)

          1.搭建beans层,构建实体类,以及hirbernate的小配置文件(.hbm.xml)

     

     

     2.搭建dao层以及dao的实现

     

     

     3.构建service进行业务的处理以及dao的植入

       

       

第二步:构架配置文件applicationContext.xml(关联hirbernate以及struts的配置)    

<?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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 配置dao -->
<bean id="stockdao" class="cn.hq.dao.impl.StockDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 配置service -->
<bean id="service" class="cn.hq.service.impl.StockServiceImpl">
<property name="stockDao" ref="stockdao"></property>
</bean> <!-- 配置jdbc连接 -->
<context:property-placeholder location="classpath:jdb.properties"/> <!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>

    <!--hirbernate  SessionFactory配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!--各种hibernate属性 -->
<property name="hibernateProperties">
<props>
<!-- 方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext</prop>
</props>
</property>
<!-- 引入小配置 -->
<!-- <property name="mappingResources" value="cn/hq/beans/Stock.hbm.xml"></property> -->
<property name="mappingDirectoryLocations" value="classpath:cn/hq/beans"></property>
</bean>

    <!-- struts2 配置action              scope   范围-->
<bean id="addStock" class="cn.hq.action.AddStockAction" scope="prototype">
<property name="service" ref="service"></property>
</bean>

<!-- 事务配置 -->
<!-- 注册事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <tx:advice id="txAdive" transaction-manager="transactionManager">
<tx:attributes>
<!-- 指定方法的事务隔离机制以及传播行为 -->
<tx:method name="addStock" isolation="DEFAULT" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut expression="execution(* *..service.*.*(..))" id="stockpointcut"/>
<aop:advisor advice-ref="txAdive" pointcut-ref="stockpointcut"/>
</aop:config> </beans>

构建jdb.properties,连接数据库。


测试类:

首先测试hirbernate整合


struts2整合:

 前提: 必须在Web应用启动时,创建Spring的ApplicationContext实例 
 步骤: 采用ContextLoaderListener来创建ApplicationContext: contextConfigLocation /WEB-INF/spring-config/applicationContext.xml org.springframework.web.context.ContextLoaderListener

  构建action类

  

struts.xml配置文件:

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" extends="struts-default">
<!-- 定义action节点 指定action 指定方法 -->
<action name="addaction" class="cn.hq.action.AddStockAction" method="add">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>

applicationContext.xml中配置:

web.xml的配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name> <!--指定配置文件的位置和名称 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <!-- 监听器:作用是在整个网站运行的时候,获取到ServletContext(application)初始化的时候,自动
注入Spring容器
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

测试页面:

add.jsp


成功没有奇迹,只有轨迹。

       ---告诫自己

SSH整合,必出精品的更多相关文章

  1. EMCA常用命令 【weber整理必出精品】

    EMCA常用命令 创建一个EM资料库 emca -repos create 重建一个EM资料库 emca -repos recreate 删除一个EM资料库 emca -repos drop 配置数据 ...

  2. vi 快捷键【转】【weber整理必出精品】

    光标的移动 命令 光标移动 h或^h 向左移一个字符 j或^j或^n 向下移一行 k或^p 向上移一行 l或空格 向右移一个字符 G 移到文件的最后一行 nG 移到文件的第n行 w 移到下一个字的开头 ...

  3. 【Java EE 学习 67 下】【OA项目练习】【SSH整合JBPM工作流】【JBPM项目实战】

    一.SSH整合JBPM JBPM基础见http://www.cnblogs.com/kuangdaoyizhimei/p/4981551.html 现在将要实现SSH和JBPM的整合. 1.添加jar ...

  4. 全世界最详细的图形化VMware中linux环境下oracle安装(二)【weber出品必属精品】

    <ORACLE 10.2.05版本的升级补丁安装> 首先我们解压 $ unzip p8202632_10205_LINUX.zip 解压后我们会发现多出了个文件夹,他是:Disk1,进入D ...

  5. SSH整合方案2

    [案例3]SSH整合_方案2 **  案例描述  两个知识点的演示  其一,SSH整合的第二个方案  其二,Spring+JDBC+Struts2  参考代码  31) 使用工程spring4  32 ...

  6. 从MVC和三层架构说到SSH整合开发

    相信很多人都认同JavaWeb开发是遵从MVC开发模式的,遵从三层架构进行开发的,是的,大家都这么认同.但是相信大家都会有过这样一个疑问,if(MVC三层模式==三层架构思想)out.println( ...

  7. ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存

    ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate  : Hibernate是一个持久层框架,经常访问物理数据库 ...

  8. SSH整合:Unable to instantiate Action, employeeAction, defined for 'emp-list' in namespace '/'employeeAction - action

    SSH整合,照着视频敲的,不知为何会报错,经历了快两周的折磨给解决了.记录下来给后面需要帮助的人,也算极好的了. Struts Problem Report Struts has detected a ...

  9. ssh整合学习(1)

    Hibernate框架 1 hibernate核心配置文件 (0)orm思想 -对象关系映射 (1)数据库信息 (2)hibernate信息 (3)映射配置 (4)hibernate核心配置文件 -如 ...

随机推荐

  1. javascript for循环

    2016年12月28日 20:01:54 星期三 html: <a href="aaaa">AAAA</a> <a href="bbbb&q ...

  2. MAC上向GitHub上上传自己的项目

    1首先需要在github上创建你自己的github账户 2新建仓库(注意选择initialize this repository with a README) 3生成ssh(公钥.pub&私钥 ...

  3. js_闭包

    先从闭包特点解释,应该更好理解.闭包的两个特点:1.作为一个函数变量的一个引用 - 当函数返回时,其处于激活状态.2.一个闭包就是当一个函数返回时,一个没有释放资源的栈区.其实上面两点可以合成一点,就 ...

  4. 「C++11」Lambda 表达式

    维基百科上面对于 lambda 的引入是如下描述的: 在标准 C++,特别是当使用 C++ 标准程序库算法函数诸如 sort 和 find.用户经常希望能够在算法函数调用的附近定义一个临时的述部函数( ...

  5. 如何封装JS ----》JS设计模式《------ 封装与信息隐藏

    1. 封装与 信息隐藏之间的关系 实质是同一个概念的两种表达,信息隐藏式目的,二封装是借以达到目的的技术方法.封装是对象内部的数据表现形式和实现细节,要想访问封装过额对象中的数据,只有使用自己定义的操 ...

  6. 将数据导入Excel

    /** * 查询未打印订单 * @param req * @param sort * @param order * @param rows * @param page * @return */ pub ...

  7. CC2540自己的配置文件

    首先要指出,字段属性有notify的不能同时有read,write属性,别问哥,哥也不知道,反正我做的就不能notify,只能read,write. 分享的程序段第一字段有notify属性,第二字段r ...

  8. xcode 8 重新支持插件

    苹果出了Xcode8之后,就加了签名让之前的自定义插件无法继续的安装使用.想要重新使用插件的话只要用自己的签名覆盖苹果的签名即可. 1.创建自签名证书 钥匙串->钥匙串访问->证书助理-& ...

  9. iOSIPV6简单测试环境搭建

    应苹果官方要求,iOS应用必须适配IPV6才能通过审核,这里分享一个简单的ipv6测试方法 一.工具原料 1.1 Mac电脑一台 1.2 iPhone手机两部 1.3 数据线一根 二.步骤方法 2.1 ...

  10. git pull push 不用输入用户名和密码的方法

    1.在计算机的安装盘下找到 '用户' 这个文件夹打开. 2.找到'用户' 文件夹下面你当前的用户. 3.新建'.gitconfig' 文件 4. [user] email =  name = [pus ...