SSH的整合

struts2和hibernate的配置我这里就不多说了,先把两个有关的东西说下。一个是所有的包。struts2+hibernate3+spring2.5我包准备放上去给大家下载。

http://www.baidupcs.com/file/d11017c37f155eeaa2c930797efe84d4?xcode=ac52c41879e48026c5725c2c8bdd8501150b9185cf21e87b&fid=3307409781-250528-1315243302&time=1375278072&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-swgcOMM1k9n9XKyhIeUVA40Uaac%3D&to=wb&fm=N,N,T&expires=8h&rt=pr&r=283601240&logid=2551046797

放在的我百度云盘里面

闲话不说:开始。

先是struts2和hibernate的配置

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <!-- structs2的配置 -->
    <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>
 
</web-app>

然后在src下添加一个struts.xml:

<?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>
</struts>

然后在src下添加一个hibernate.cfg.xml:(这是一些数据库的配置)

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">
jdbc:jtds:sqlserver://localhost:1433;DatabaseName=LQQ
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<!--<property name="myeclipse.connection.profile">
LoginSystem
</property> -->
<property name="connection.password">sa</property>
<property name="connection.driver_class">
net.sourceforge.jtds.jdbc.Driver
</property>
<property name="show_sql">true</property>
<!-- POJO 类映射配置-->
<mapping resource="sedion/xq/ORM/Stuinfo.hbm.xml" />
</session-factory>
</hibernate-configuration>

重点讲Spring:
1. 在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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 这是个例子待会会用到 可以先不要 -->
<bean id="TUser_id" class="test.TUser">
<property name="username" value="你"></property>
<property name="allname" value="李"></property>
<property name="address" value="温州市"></property>
</bean> </beans>

2.Spring基本配置完毕

下面我们测试下:src建个test包

建两个类User和SpringTest类:

public class User implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String username;
private String allname;
private String address; public String getUsername() {
return this.username;
} public void setUsername(String username) {
this.username = username;
} public String getAllname() {
return this.allname;
} public void setAllname(String allname) {
this.allname = allname;
} public String getAddress() {
return this.address;
} public void setAddress(String address) {
this.address = address;
}
public class SpringTest {
    public static void main(String[] args) {
        // 加载spring配置文件,初始化IoC容器
        ApplicationContext ac = new ClassPathXmlApplicationContext(
                "applicationContext.xml");
        // 从容器 接管Bean
        TUser user = (TUser) ac.getBean("TUser_id");
        // 输出欢迎信息
        System.out.println("Hello:" + user.getUsername() + ";u is in "
                + user.getAddress() + " ; and u is  " + user.getAllname());
    }
}
<br><br>

别忘了:在applicationContext.xml中配置一个bean,在xml中增加如下代码:

<!-- 这是个例子待会会用到  可以先不要 -->
  <bean id="TUser_id" class="test.TUser">
        <property name="username" value="你"></property>
        <property name="allname" value="李"></property>
        <property name="address" value="温州市"></property>
    </bean>

运行main方法后

控制台出现:Hello:你;u is in 温州市 ; and u is  李

下面开始整合

整合struts2

1.整合struts2配置web.xml文件。在web.xml中加入以下代码:

<!-- Spring与Struts的整合其实就是把Struts的Action类交给Spring来管理 -->
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener  
    </listener-class>
</listener>

2.举个例子:

  把struts的action交给spring:

  先把

<action name="login" class="test.LoginAction ">

改为

<action name="login" class="loginAction_id">

然后在

在applicationContext.xml中增加如下代码:

<bean id="loginAction_id" class="test.action.LoginAction" scope="prototype">
</bean>

整合Hibernate

Spring整合Hibernate主要是对hibernate的Session进行管理,包含Session的创建、提交、关闭的整个生命周期。Spring对事务的管理应用了AOP的技术

1)        配置sessionFactory,让spring来创建Session。

我们原来是用HibernateSessionFactory.java来创建Session的,现在删除即可,交给Spring创建。(这样就spring来整合hibernate来创建session)

这里,创建了一个Session工厂类的Bean,其ID为“sessionFactory”.

在applicationContext.xml中增加如下代码:

<!-- 配置sessionFactory -->
 
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 
     <property name="configLocation">
 
         <value>classpath:hibernate.cfg.xml</value>
 
     </property>  
 
 </bean>  

还有个例子上的配置:

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                        <value>sedion/xq/bean/User.hbm.xml</value><!--这里是将映射文件加载-->
            </list>
        </property>
 
    </bean>

2.

然后DAO层匹配一个session工厂,<ref bean="sessionFactory"/>这个sessionFactory是指session工厂的ID。

<bean id="userDao" class="sedion.xq.dao.iml.UserDAOImpl" scope="singleton">
 
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
</bean>

3.service层调用DAO层

     <bean id="userService" class="sedion.xq.sevice.iml.UserServiceImpl">
    <property name="userDAO" ref="userDao"></property>
</bean>

然后就是各个action调用service层:(随便写个)

<bean id="saveUesrAction" class="sedion.xq.action.user.SaveUserAction"
    scope="prototype">
    <property name="userService" ref="userService"></property>
</bean>

整合就这样好

下面是整合下载的例子。

http://www.baidupcs.com/file/e2a9b7b37f5a2b8e5c69ea3c36930ccc?xcode=9b9ef9bca971b10354ce947d1fdbc0111ad451c9893bdd6d&fid=3307409781-250528-3304344922&time=1375282368&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-LkzEcKCUIYTYWK4aPUSsOPbS5yY%3D&to=wb&fm=N,N,T&expires=8h&rt=pr&r=613900100&logid=1529936272

 
 
分类: javaSSH
标签: javassh整合SSH

SSH的整合的更多相关文章

  1. SSH框架整合

    SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...

  2. ssh注解整合

    ssh注解整合 导入java包 配置struts2环境 1. 创建struts.xml配置文件 <?xml version="1.0" encoding="UTF- ...

  3. SSH项目整合教学Eclipse搭建SSH(Struts2+Spring3+Hibernate3)

    这篇博文的目的 尝试搭建一个完整的SSH框架项目. 给以后的自己,也给别人一个参考. 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创建Struts项目,整合Hiberna ...

  4. dwr与ssh框架整合教程

    (1)dwr与ssh框架整合教程dwr框架介绍. DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开 发人员开发包含AJ ...

  5. ssh框架整合之登录以及增删改查

    1.首先阐述一下我用得开发工具,myeclipse2017+oracle,所以我的基本配置步骤可能不一样,下面我用几张图来详解我的开发步骤. ---1先配置structs (Target 选择apac ...

  6. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  7. J2EE进阶(十)SSH框架整合常见问题汇总(一)

    SSH框架整合常见问题汇总(一) 前言 以下所列问题具有针对性,但是遇到同类型问题时均可按照此思路进行解决. HTTP Status 404 - No result defined for actio ...

  8. MVC+Spring.NET+NHibernate .NET SSH框架整合 C# 委托异步 和 async /await 两种实现的异步 如何消除点击按钮时周围出现的白线? Linq中 AsQueryable(), AsEnumerable()和ToList()的区别和用法

    MVC+Spring.NET+NHibernate .NET SSH框架整合   在JAVA中,SSH框架可谓是无人不晓,就和.NET中的MVC框架一样普及.作为一个初学者,可以感受到.NET出了MV ...

  9. SSH框架整合的其它方式

    --------------------siwuxie095 SSH 框架整合的其它方式 1.主要是整合 Spring 框架和 Hibernate 框架时,可以不写 Hibernate 核心配置文件: ...

随机推荐

  1. Webbrowser控件史上最强技巧全集

    原文:Webbrowser控件史上最强技巧全集 Webbrowser控件史上最强技巧全集 VB调用webbrowser技巧集 1.获得浏览器信息: Private Sub Command1_Click ...

  2. dojo的TabContainer添加ContentPane假设closable,怎么不闭幕后予以销毁ContentPane

    其主要思想是新的TabContainer的扩展类,重载其closeChild属性,使得其在关闭子容器时.不调用该子容器的destroyRecursive方法. define([ "dojo/ ...

  3. java通过SVG导出图片

    import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import ja ...

  4. Java遍历解析URL类型字符串中参数

    public static void main(String[] args) { String str="&emailCheckURL=447&useremail=vip@c ...

  5. 使用Dropbox+Justwriting+Markdown建立个人博客

    使用Dropbox+Justwriting+Markdown建立个人博客,让您真正体会到什么是"简化". 您的博客所有日志存储在您的PC上.即使有一天你的server主机挂了,你的 ...

  6. Codeforces 429 A. Xor-tree

    下来的第一次相遇是在不翻盖的同一节点,递归可以是.... A. Xor-tree time limit per test 1 second memory limit per test 256 mega ...

  7. Linux下防火墙设置

    Linux下开启/关闭防火墙命令  1) 永久性生效,重启后不会复原 开启:chkconfigiptables on 关闭:chkconfigiptables off 2) 即时生效,重启后复原 开启 ...

  8. leetcode第35题--Valid Sudoku

    题目:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  9. shell 水平测试

    http://bbs.chinaunix.net/thread-476260-1-1.html 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  10. .NET编程和SQL Server ——Sql Server 与CLR集成 (学习笔记整理-1)

    原文:.NET编程和SQL Server ——Sql Server 与CLR集成 (学习笔记整理-1) 一.SQL Server 为什么要与CLR集成 1. SQL Server 提供的存储过程.函数 ...