SSH整合

OA项目: SHH框架的整合

1.       数据库(mysql)的创建: create databases myoa default character set utf8;

2.       查看创建的数据 show create database myoa;

 

Contr+shift+t: 查找方言

Alt+shit+a快速去除重复的字段

Spring :

 

SHH框架整合:

springstruts整合:

 

1.创建数据库

 

       C:\Documents and Settings\Administrator>mysql -uroot -proot

      

       mysql> create database myoa default character set utf8;

       Query OK, 1 row affected (0.03 sec)

 

       mysql> show create database myoa;

       +----------+---------------------------------------------------------------+

       | Database | Create Database                                               |

       +----------+---------------------------------------------------------------+

       | myoa     | CREATE DATABASE `myoa` /*!40100 DEFAULT CHARACTER SET utf8 */ |

       +----------+---------------------------------------------------------------+

       1 row in set (0.00 sec)

 

 

2.创建web项目

       创建Web项目名为: MyOA

       设置项目的编码方式为utf-8  . 设置后默认项目下所有文件与utf-8编码方式

       项目名右击-->properties->Resource-->Text file encoding->Other-->UTF-8

 

3.配置环境

       3.1 Struts2环境搭建(该环境适用于javaEE5)

              3.1.1导入jar struts

                     struts-2.3.1.1\apps\struts2-blank-2.x.war \WEB-INF\lib\下所有jar

                     commons-fileupload-1.2.1.jar

                 commons-lang-2.5.jar

                 commons-io-1.3.2.jar

                 freemarker-2.3.15.jar

                 javassist-3.12.0.GA.jar

                  mysql-connector-java-5.1.5-bin.jar

                 ognl-2.7.3.jar

                 struts2-core-2.1.8.1.jar

                 xwork-core-2.1.6.jar

 

              3.1.2 配置 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">

                     <!--配置Struts2主过滤器 -->

                            <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> //* :表示过滤所有的url请求

                            </filter-mapping>

                     </web-app>

 

              3.1.3 配置 struts.xml

                     window-->Preferences-->xml --> xml Catalog--> 导入struts-2.0.dtd 或者2.5.*.dtd都可以.

                     url: http://struts.apache.org/dtds/struts-2.0.dtd

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

                            <!-- 设置为开发模式作用当配置文件改变时无需重新部署 -->

                         <constant name="struts.devMode" value="true" />

                            <!-- Action的扩展名设为action -->

                            <constant name="struts.action.extension" value="action" />

                            <name:包名,可以随便写,最好使用该类当前的包名, namespace:命名空间,

                         <package name="xxx" namespace="/" extends="struts-default">

                            <action name="自定义" class="action类所在的路径">

                                   <result>/WEB-INF/success.jsp</result>//返回到指定的页面

                            </action>

<result input=”错误的/返回页面”>/WEB-INF/success.jsp</result>                     </package>

                     </struts>

3.1.3测试struts环境搭建:

: 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开发模式-->

    <constant name="struts.devMode" value="true"/>

    <!-- 配置扩展名 -->

    <constant name="struts.action.extension" value="action"/>

    <!-- 声明唯一的包名,主要用与装配aciton,  namespace为包名的命名空间-->

    <package name="mydefault" namespace="/" extends="struts-default">

           <!-- 配置总页面,TotalPageAction 用户管理-->

       <action name="total_*" class="totalPageAction" method="{1}">

           <result name="{1}">/WEB-INF/totalpage/{1}.jsp</result>

       </action>

</struts>

 

1. Struts2未整合之前测试(在只是导入如strutsjar包时测试如下)

src下创建包例: com.tu.myoa.test , 编写 TestAction 测试类

       publicclass TestAction extends ActionSupport{

    public String execute() throws Exception {

       System.out.println("TestAction.execute()");

       return"success";

    }

}                  

简单测试使用的jsp页面 test.jsp

<%@ page language="java"  pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

      <body>

          Struts2测试成功

      </body>

</html>

 

3. 部属,开启tomcat      服务器

打开IE 输入: http://127.0.0.1:8080/MyOA/test.action

网页中打印出:  Struts2测试成功, 后台Console打印 : TestAction.execute()... ,则表示Struts正常工作 , 可以开始进行整合

 

3.2 Hibernate环境搭建

       3.2.1 hibernate框架需要导入的jar

       hibernate-distribution-3.5.6-Final\ 目录

       Hibernate3.jar   --->hibernate核心包  3.5.6版本

 

       其它为hiberante所依赖的jar

       hibernate-distribution-3.5.6-Final\lib\required目录

       antlr-2.7.6.jar

       commons-collections-3.1.jar

       dom4j-1.6.1.jar

       javassist-3.9.0.GA.jar

       jta-1.1.jar

       slf4j-api-1.5.8.jar

 

       hibernate-distribution-3.5.6-Final\lib\jpa目录

                 hibernate-jpa-2.0-api-1.0.0.Final.jar    --不加会报错              

       hibernate-distribution-3.5.6-Final\lib\optional\c3p0目录

                c3p0-0.9.1.jar

 

3.2.2 编写配置文件 hibernate.cfg.xml

       样板可以在hibernate-distribution-3.5.6-Final\project\etc目录下可以找到

       配置  http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd

                     <?xml version='1.0' encoding='utf-8'?>

                     <!DOCTYPE hibernate-configuration PUBLIC

                            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

                            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

                     <hibernate-configuration>

                         <session-factory>

                            <!-- 连接数据库属性-->

                            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

                            <property name="connection.url">jdbc:mysql://127.0.0.1:3306/创建的数据库名</property>

                            <property name="connection.username">root</property>

                            <property name="connection.password">root</property>

                            <!-- 是否显示SQL语句 -->

                            <property name="show_sql">true</property>

                            <!-- SQL 语句方言 -->

                            <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

                            <!-- 自动创建表 ,如果表已经存在,不在新建表,没有存在,则新建表-->

                            <property name="hibernate.hbm2ddl.auto">update</property>

                            <!-- 加载域对象和表的映射文件类路径, *:表示实体类名,即对象/映射关联,:该文件的类名必须和创建的类名相同.

                            <mapping resource=" xxx.hbm.xml"/>-->

                         </session-factory>

                     </hibernate-configuration>

                    

              3.2.3 编写映射文件 xxx.hbm.xml

                     配置  http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd

                     编写样板:

                     <?xml version="1.0"?>

                     <!DOCTYPE hibernate-mapping PUBLIC

                            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

                            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

                     <hibernate-mapping>

                            <class name="类名" table="对应的数据库中创建的表名">

                                   <id name="类中属性名">

                                          //navite表示按照数据底层自动增长id的值

                                          <generator class="navite"/>

                                   </id>

                                   <property name="类中属性名"/>

                            </class>

                     </hibernate-mapping>

 

       3.3 Spring环境搭建

              3.3.1 导入Spring核心包

                     spring-framework-2.5.5\dist目录下

                            spring.jar

 

                     导入Spring所依赖的jar

                            spring-framework-2.5.5\lib\aspectj目录下  ---> SpringAOP切面编程技术

                            aspectjrt.jar

                            aspectjweaver.jar

 

                     AOP切面编程所依赖的技术  动态代理和cglib 

                            spring-framework-2.5.5\lib\cglib目录下

                                   cglib-nodep-2.1_3.jar 

 

                     spring-framework-2.5.5\lib\log4j目录下

                            log4j-1.2.15.jar 

                     spring-framework-2.5.5\lib\jakarta-commons 日志包,显示操作出现的不正确信息

                            commons-logging.jar

                    

              3.3.2 配置文件 applicationContext.xml

                     配置  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd          --beans配置

                            http://www.springframework.org/schema/context/spring-context-2.5.xsd --context配置

                            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd          --事务配置

 

                     <?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:tx="http://www.springframework.org/schema/tx"

                                   xsi:schemaLocation="http://www.springframework.org/schema/beans

                                   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

                                                 http://www.springframework.org/schema/context

                                                 http://www.springframework.org/schema/context/spring-context-2.5.xsd

                                                 http://www.springframework.org/schema/tx

                                                 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

                           

                     <!-- 自动扫描指定的目录下的所有类并装配bean(实体)到容器中 -->

                     <context:component-scan base-package="com.tu.myoa"></context:component-scan>

                     </beans>

 

      

3.3.3.配置Springweb.xml中的监听器

       配置用于创建容器对象的监听器 , 配置方法在帮助文档中有:

              打开 spring-framework-2.5.5\docs\reference\html_single\index.html152  -- 15.2. Common configuration

       web.xml中增加如下代码:                     

    <!-- 配置spring用于创建容器的监听器 -->

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <context-param>

       <param-name>contextConfigLocation</param-name>

       <param-value>classpath:applicationContext*.xml</param-value>

    </context-param>

以上是在src目录下配置,如果是WEB-INF需要增加路径即: /WEB-INF/ applicationContext*.xml

                   

3.4单元测试环境搭建

              工程下右击-->Build Path--> Add Libraries... --> JUnit --> Junit4 --> Finish ,也可以直接使用注解在方法上写@Test, 主要作用是:在不用写main()函数时,可以直接运行测试代码.非常实用

             

4.SSH整合

              4.1.1 整合Struts2Spring

                     4.1.1.1                 

                            所谓整合是在4.1.1.3 配置 struts.xml文件的<action class="xxx"/> 中的 xxx

                            <!-- 配置测试用的Action

                                   Struts2Spring为整合前,class属性写类的全名

                                   Struts2Spring为整合后,class属性写bean的名称(或类的全名).

                                   为了查看是否Spring是否注入成功则将class设置成bean的名称

                                   因为在applicationContext.xml文件中设置了自动扫描包下注解-->

                            <!-- 配置测试用的Action -->

                            <action name="test" class="testAction">

                                   <result name="success">/test.jsp</result>

                            </action>

 

                     4.1.1.2 整合需要导入的包  Spring容器去拿bean对象

                            SpringStruts2整合需要使用到的jar

                            struts-2.3.1.1\lib目录下

                            struts2-spring-plugin-2.3.1.1.jar

 

                     4.1.1.3 配置Springweb.xml中的监听器

                            配置用于创建容器对象的监听器,  配置方法在帮助文档中有:

                                   打开 spring-framework-2.5.5\docs\reference\html_single\index.html

                                   152  -- 15.2. Common configuration

                            web.xml中增加如下代码:

                            <!-- 配置Spring的用于创建容器对象的监听器 -->

                            <listener>

                              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

                            </listener>

                            <context-param>

                              <param-name>contextConfigLocation</param-name>

                              <param-value>applicationContext*.xml</param-value> // src目录下配置,如果是WEB-INF需要增加路径即: /WEB-INF/ applicationContext*.xml

                            </context-param>

 

                     4.1.1.4 成功页面修改test.jsp成如下:

                              <body>

                                Struts2测试成功<br/>

                                Struts2Spring环境整合成功

                              </body>

 

4.1.2 Struts2Spring整合后测试

                     4.1.2.1 在需要测试的bean类中增加注解

                             TestAction 测试类

                            // @Controller("testAction")  默认bean名称为类名的头字母小写,也可以不写

                            @Controller    //添加注解,Spring自动注入

                            public class TestAction extends ActionSupport{

                                   public String execute() throws Exception {

                                          System.out.println("TestAction.execute()...");

                                          return this.SUCCESS;

                                   }

                            }

                           

                     4.1.2.2 创建com.tu.myoa.test包编写 SpringTest.java 测试类

                           import org.springframework.context.ApplicationContext;

                            import org.springframework.context.support.ClassPathXmlApplicationContext;

                            public class SpringTest {

                                   //加载配置文件,并初始化bean

                            private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

                                   @Test     //使用 @Test 单元测试

                                   public void testSpring() throws Exception {

                                          //bean名称相同,使用自动注入,名称为类名头字母改小写

                                          TestAction testAction = (TestAction) ac.getBean("testAction"); 

                                          System.out.println(testAction); //打印出哈希值表示Spring通过

                                   }

                            }

                    

                  结果 :进行测试后出现:  com.tu.myoa.test.TestAction@175d6ab 结果表示Spring环境配置成功可以进行整合

                    

                     4.1.1.3

                            部属,开启tomcat   服务器

                            打开IE 输入: http://127.0.0.1:8080/MyOA/test.action 或刷新此页面

                            网页中打印出:   Struts2测试成功

                            Struts2Spring环境整合成功

                            后台Console打印 : TestAction.execute()... 

                            则表示StrutsSpring整合成功

 

       4.2 HibernateSpring整合  SpringIOC容器管理SessionFactory.管理事务

              4.2.1 配置一个beanSpring管理: SessionFactory

                     4.2.1.1 去除hibernate.xml中的数据连接信息.

                            因为这些数据都教给Spring来进行管理配置,不然会出现重复.

                            <!-- 连接数据库属性-->

                            <!-- 将数据删除或注释 

                            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

                            <property name="connection.url">jdbc:mysql://127.0.0.1:3306/myoa</property>

                            <property name="connection.username">root</property>

                            <property name="connection.password">root</property>-->

 

                            配置属性文件:db.properties

                            url=jdbc:mysql:///myoa //连接数据库的url

                            driverClass=com.mysql.jdbc.Driver//连接驱动

                            username=root//登录数据库的用户名

                            password=root //密码

 

                     4.2.1.2 编写 applicationContext.xml

                            编写增加以下内容:

                            <!-- 自动扫描包下所有的bean并装配bean -->

                            <context:component-scan base-package="cn.itcast.oa"/>

                           

                            <!-- 加载外部的properties配置文件 ,用于取得连接数据库信息-->            

                            <context:property-placeholder location="classpath:db.properties"/>

 

                            <!-- 配置SessionFactory Spring管理Hibernate SessionFactory 对象

                                   但因为SessionFactory是一个接口,不能生成实现类,所以需要编写实现类

                                   hibernate3中有一个实现类专门是做整合使用的类:LocalSessionFactoryBean

                            --><!-- org.springframework.orm.hibernate3.LocalSessionFactoryBean -->

                            <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

                                   <!-- 配置hibernate.cfg.xml主配置文件路径 -->

                                   <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>

                                   <!-- 配数据源 -->

                                   <property name="dataSource">

                                          <bean class="com.mchange.v2.c3p0.ComboPooledDataSource"> 

                                     <!-- 配置数据库连接信息 ,使用${}EL表达式的形式从属性文件中取值,注意配置以上 db.properties 属性文件,注意要换行写,每行行尾不能有空格-->

                                                 <property name="jdbcUrl" value="${jdbcUrl}"></property>      

                                                 <property name="driverClass" value="${driverClass}"></property>

                                                 <property name="user" value="${username}"></property>

                                                 <property name="password" value="${password}"></property>

                                                 <!-- 配置C3p0时的配置信息详情查看c3p0帮助方档

                                                 打开: c3p0-0.9.1.2\doc\index.html

                                                 在附录Appendix A: Configuration Properties 配置相中有所有配置信息-->

                                                  <!-- 其他和管理配置 -->

                                                 <!--初始化时获取三个连接,取值应在minPoolSizemaxPoolSize之间。Default: 3 -->

                                                 <property name="initialPoolSize" value="3"></property>

                                                 <!--连接池中保留的最小连接数。Default: 3 -->

                                                 <property name="minPoolSize" value="3"></property>

                                                 <!--连接池中保留的最大连接数。Default: 15 -->

                                                 <property name="maxPoolSize" value="5"></property>

                                                 <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->

                                                 <property name="acquireIncrement" value="3"></property>

                                                 <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatementsmaxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->

                                                 <property name="maxStatements" value="8"></property>

                                                 <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->

                                                 <property name="maxStatementsPerConnection" value="5"></property>

                                                 <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->

                                                 <property name="maxIdleTime" value="1800"></property>

                                          </bean>

                                   </property>

                            </bean>

                           

                     4.2.1.3 测试 SessionFactory

                            SpringTest.java中编写如下测试代码:

                            //测试sessionFactory是否注入到容器中,dao层做准备

                            @Test

                            public void testSessionFactory() throws Exception {

                                   SessionFactory sessionFactory = (SessionFactory) ac.getBean("sessionFactory");

                                   System.out.println(sessionFactory);

                            }

 

               4.2.2 配置Spring管理事务

                     4.2.2.1 配置编写 applicationContext.xml

                            编写增加以下内容:

                            <!-- Spring管理事务配置声明式事务管理(采用基于注解的配置) -->

                            <bean id="ttransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

                                   <property name="sessionFactory" ref="sessionFactory"></property>

                            </bean>

                            <tx:annotation-driven transaction-manager="transactionManager"/>

                    

                     4.2.2.2 编写测试准备创建事务测试类

                            编写一个Service做测试准备com.tu.myoa.test包中TestService.java模拟向数据库增加数据

                            @Service  //注入注解默认bean名称:testService

                            public class TestService {

                                   @Resource  //注入sessionFactory

                                   private SessionFactory sessionFactory;

                                   @Transactional      // 事务注解

                                   public void addUsers() {

                                          //获取Spring帮我们管理的Session  就一定要调用getCurrentSession();

                                          Session session =sessionFactory.getCurrentSession();

                                          session.save(new User());

                                          //int a = 1 / 0;               //异常测试是否会回滚

                                          session.save(new User());

                                   }

                            }

                    

                     4.2.2.3 编写测试准备  创建实体

                            4.2.2.3.1 编写 domain User

                                   com.tu.myoa.domain包中创建一个实体.

                                   package com.tu.myoa.domain;

                                   public class User {

                                          private Long id;

                                          private String name;

                                          public Long getId() {

                                                 return id;

                                          }

                                          public void setId(Long id) {

                                                 this.id = id;

                                          }

                                          public String getName() {

                                                 return name;

                                          }

                                          public void setName(String name) {

                                                 this.name = name;

                                          }

                                   }

                            4.2.2.3.2 配置User.hbm.xml文件如下:

                                          配置代码提示: hibernate-mapping-3.0.dtd

                                          <?xml version="1.0"?>

                                          <!DOCTYPE hibernate-mapping PUBLIC

                                                 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

                                                 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

                                          <hibernate-mapping package="com.tu.myoa.domain">

                                                 <class name="User" table="myoa_user">

                                                        <id name="id">

                                                               <generator class="native"/>

                                                        </id>

                                                        <property name="name" />

                                                 </class>

                                          </hibernate-mapping>

 

                            4.2.2.3.3 编写配置文件 hibernate.cfg.xml (对象/关系映射文件)

                                          :3.2.2 <!-- 加载域对象和表的映射文件类路径

                                                 <mapping resource="xxx.hbm.xml"/>-->

                                          跟改为如下:

                                   <mapping resource="com/tu/myoa/domain/User.hbm.xml" />

 

                            4.2.2.3.4  SpringTest.java中增加如下测试方法

                                   //测试事务

                                   @Test

                                   public void testServiceTransaction() throws Exception {

                                          TestService testService = (TestService) ac.getBean("testService");

                                          testService.addUsers(); //增加用户

                                   }

 

                            4.2.2.3.5 测试整合SSH

                                   运行以上代码:SpringTesttestServiceTransaction()方法

                                   控制平台打印:则表示成功,整合SSH成功

                                          com.tu.myoa.test.TestAction@ee6ad6

                                          org.hibernate.impl.SessionFactoryImpl@10d0eae

                                          Hibernate: insert into myoa_user (name) values (?)

                                          Hibernate: insert into myoa_user (name) values (?)

                                   mysql> select * from myoa_user;

                                   +----+------+

                                   | id | name |

                                   +----+------+

                                   |  1 | NULL |

                                   |  2 | NULL |

                                   +----+------+

                                   2 rows in set (0.00 sec)

                                   查询数据库中的数据如果有两条数据则表示成功.

 

                            4.2.2.3.6 测试事务

                                   修改 TestService类中的 addUsers 方法为如下:

                                   @Transactional      // 事务注解

                                   public void addUsers() {

                                          //获取Spring帮我们管理的Session  就一定要调用getCurrentSession();

                                          Session session =sessionFactory.getCurrentSession();

                                          session.save(new User());

                                          int a = 1 / 0;          //异常测试是否会回滚  <--<---

                                          session.save(new User());

                                   }

                                   重新运行测试方法: SpringTest. testServiceTransaction方法;

                                   出现异常:

                                   mysql> select * from myoa_user;

                                   +----+------+

                                   | id | name |

                                   +----+------+

                                   |  1 | NULL |

                                   |  2 | NULL |

                                   |  4 | NULL |

                                   |  5 | NULL |

                                   +----+------+

                                   4 rows in set (0.00 sec)

                                   当出现少有一个id,则表示事务回滚成功.

 

                           

       4.3 测试SSH整合

              4.3.1 编写测试代码

                     @Controller("testAction")

                     public class TestAction extends ActionSupport {

                            //SSH最近整合测试.使用Spring注入

                            @Resource

                            private TestService ts ;          //<-----

                            public String execute() throws Exception {

                                   System.out.println("TestAction.execute()...");

                                   //SSH最近整合测试.

                                   //TestService ts = new TestService();   //当使用时Spring后就不需要new

                                   ts.addUsers();               

                                   return this.SUCCESS;

                            }

                     }

              4.3.2 编写 test.jsp 测试整合

                       <body>

                         Struts2环境测试成功<br/>

                         Struts2Spring环境整合成功<br/>

                             hibernateSpring环境整合成功<br/>

                         SSH整合成功

                       </body>

 

                     部署开启 tomcat服务器

                            打开IE 输入地址: http://127.0.0.1:8080/MyOA/test.action

                            内页打印:

                                          Struts2测试成功

                                          Struts2Spring环境整合成功

                                          SSH整合成功

                     并控制台打印如下内容:

                            TestAction.execute()...

                            Hibernate: insert into myoa_user (name) values (?)

                            Hibernate: insert into myoa_user (name) values (?)

 

                     查询MySQL数据库:

                            mysql> select * from myoa_user;

                     出现如下则成功:

                            +----+------+

                            | id | name |

                            +----+------+

                            |  1 | NULL |

                            |  2 | NULL |

                            |  4 | NULL |

                            |  5 | NULL |

                           +----+------+

 

                     至此表示三大框架SSH整合完必.

 

 

:以上版本适用于javaEE5,javaEE6需要使用3.0版本的其他包,如果使用javaEE6的则会出现sessionFactory不能注入错误信息

shh所需要的jar,即配置文件如下:javaEE5环境总共有24jar

 

antlr-2.7.6.jar

aspectjrt.jar

aspectjweaver.jar

c3p0-0.9.1.jar

cglib-nodep-2.1_3.jar

commons-collections-3.1.jar

commons-fileupload-1.2.1.jar

commons-io-1.3.2.jar

commons-logging.jar

dom4j-1.6.1.jar

freemarker-2.3.15.jar

hibernate-jpa-2.0-api-1.0.0.Final.jar

hibernate3.jar

javassist-3.12.0.GA.jar

jta-1.1.jar

log4j-1.2.15.jar

mysql-connector-java-5.1.5-bin.jar

ognl-2.7.3.jar

slf4j-api-1.5.0.jar

slf4j-log4j12-1.5.0.jar

spring.jar

struts2-core-2.1.8.1.jar

struts2-spring-plugin-2.1.8.1.jar

xwork-core-2.1.6.jar

 

需要配置的文件:

 

applicationContext.xml //主要用于加包下面的实体bean,直接在压缩包搜索即可,文件名不能修改

db.properties //属相文件,后缀必须为properties,主要存一些经常变换的属性,键值对存储形式,key=value

User.hbm.xml //实体/关系映射文件,主要是实体对象的属性和表之间的对应,文件名和类名一直,类名.hbm.xml,该文件与实体bean放在一起

hibernate.cfg.xml //固定文件,不可修改文件名,主要配置数据连接信息

log4j.properties//日志记录文件,该文件需要设置,error级别,减少不必要显示的信息,配置log4j.rootLogger=error, stdout,其他带有日志级别(info,warn,debug)的全部使用#注释

struts.xml //用于配置action,文件名不可改变,只能放在src目录下.其他文件任意

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值