SSH框架基础知识及搭建步骤

来源:互联网 发布:美容院系统易语言源码 编辑:程序博客网 时间:2024/05/24 01:46
1、基于struts2,spring3,Hibernate3

2、SSH对应 struts spring hibernatestruts 采用MVC模式,主要是作用于用户交互

     spring 采用IOC和AOP~作用比较抽象,是用于项目的松耦合

     hibernate 是对象持久化框架,其实就是实体类和数据库表建立关系,操作类就会触发相应的sql语句,可以不用写任何sql语句,完成数据库编


使用步骤

1、首先分别搭建三个框架,先配置struts
          (1)、加入以下jar包  到lib
freemarker-2.3.15.jar
858.7 KB


commons-io-1.3.2.jar
85.7 KB


xwork-core-2.1.6.jar
1.5 MB


ognl-2.7.3.jar
234.2 KB


commons-fileupload-1.2.1.jar
56.4 KB


ojdbc6.jar
1.9 MB


struts2-core-2.1.8.1.jar
738.4 KB



          (2)、拷贝已有的struts.xml到src,

struts.xml
600 bytes



          (3)、拷贝已有web.xml文件,配置web.xml中和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>
     </filter-mapping>
     <listener>
 
2、配置Hibernate

          (1)、拷贝jar包到lib

                    《1》核心包一个
hibernate3.jar
4.0 MB


                    《2》
ojdbc14.jar
1.5 MB


javassist-3.12.0.GA.jar
618.5 KB


antlr-2.7.6.jar
433.0 KB


dom4j-1.6.1.jar
306.5 KB


slf4j-api-1.6.1.jar
24.9 KB


commons-collections-3.1.jar
546.3 KB


jta-1.1.jar
10.6 KB



          
          (2)、拷贝已有hibernate.cfg.xml文件到src目录下

                    
hibernate.cfg.xml
999 bytes



               内容如下
<!DOCTYPE hibernate-configuration PUBLIC
     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<!--      1、加载数据库驱动,获取数据库连接 -->
     <session-factory>
          <property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>
          <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
          <property name="hibernate.connection.username">scott</property>
          <property name="hibernate.connection.password">tiger</property>
          <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property><!-- 169.254.146.196 -->

          <!-- 显示SQL,默认为false -->
          <property name="hibernate.show_sql">true</property>

          <!-- 添加一个映射文件  与具体的Java类有关-->
           <mapping resource="com/ldl/bean/user.hbm.xml"/>
           <mapping resource="com/ldl/bean/role.hbm.xml"/>
     </session-factory>
</hibernate-configuration>

3、配置Spring
               (1)、加载jar包到lib
commons-logging.jar
59.4 KB


org.springframework.aop-3.0.7...
313.9 KB


aspectjrt.jar
112.2 KB


cglib-nodep-2.1_3.jar
316.6 KB


org.springframework.jdbc-3.0....
377.0 KB


org.springframework.context-3...
654.7 KB


org.springframework.core-3.0....
374.6 KB


org.springframework.expressio...
165.8 KB


org.springframework.transacti...
226.6 KB


aspectjweaver.jar
1.5 MB


aopalliance.jar
4.4 KB


org.springframework.asm-3.0.7...
51.8 KB


org.springframework.aspects-3...
34.5 KB



          (2)、配置applicationContext.xml以及applicationContext.xml
               
applicationContext_jdbc.xml
1.5 KB


applicationContext.xml
1.0 KB



4.整合spring和struts,目的:Action交由spring管理

 


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

                          
<context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>
              classpath:applicationContext.xml,
              classpath:applicationContext_jdbc.xml
          </param-value>
     </context-param>


1 0
原创粉丝点击