码迷,mamicode.com
首页 > 其他好文 > 详细

SSH整合

时间:2017-03-25 21:47:59      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:htm   链接   service   技术分享   names   work   html 4.01   class   plugin   

1.SSH知识点回顾
2.搭建SSH开发环境
3.struts2整合spring-->spring整和hibernate
4.案例:使用ssh框架开发人员管理系统

1.ssh知识点回顾
通常的web应用开发可以分为三层结构:"web层","业务层","持久层". 

技术分享
 2.SSH环境搭建
    * 引入struts2的jar包
    * 了解的jar包
        struts-convention-plugin-2.3.15.3.jar --struts2的注解开发的jar包
        struts-spring-plugin-2.3.153..jar   --struts2整合spring的jar包(同spring-struts)
    * hibernate框架开发相应的jar包:
        hibernate3.jar(核心)
        lib/required/*.jar
        jpa/*.jar
    * 日志的记录:
        slf4-log4j12-1.7.2.jar  --slf4j整合log4j的jar包
    * 数据库的驱动包:
    * spring的jar包:
        IOC:
         spring-beans-3.2.0.RELEASE.jar
         spring-context-3.2.0.RELEASE.jar
         spring-core-3.2.0.RELEASE.jar
         spring-expression-3.2.0.RELEASE.jar
         com.springsource.org.apache.log4j-1.2.15.jar  --记录日志
         com.springsource.org.apache.commons.loging-1.1.1.jar  --日志整合
        AOP:
         spring-aop-3.2.0.RELEASE.jar
         spring-aspects-3.2.0.RELEASE.jar
         com.springsource.org.aop.aopalliance-1.0.0.0.jar
         com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
         spring-tx-3.2.0.RELEASE.jar   --事务管理
         spring-jdbc-3.2.0.RELEASE.jar   --jdbc
         spring-test-3.2.0.RELEASE.jar   --Junit单元测试
         spring-orm-3.2.0.RELEASE.jar   --整合hibernate的包
         spring-web-3.2.0.RELEASE.jar    --整合web项目
        链接池:
         com.springsource.com.mchange.v2.c3p0-0.9.1.2 
    * 引入相应的配置文件:
        Strut2:
            web.xml  --过滤器
            struts.xml   --核心
        Spring
            web.xml  --监听器
            applacationContext.xml   --核心
        Hibernate:
            hibernate.cfg.xml --核心(可省略,配置在web.xml中)
    
  1. <!-- Struts2框架的核心配置 -->
  2. <filter>
  3. <filter-name>struts</filter-name>
  4. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</sfilter-class>
  5. </filter>
  6. <filter-mapping>
  7. <filter-name>struts</filter-name>
  8. <url-pattern>/*</url-pattern>
  9. </filter-mapping>
        在src中引入struts.xml;
        在web.xml中配置Spring核心监听器:
  1. <!-- Spring框架的核心监听器 -->
  2. <listener>
  3. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  4. </listener>
  5. <context-param>
  6. <param-name>contextConfigLocation</param-name>
  7. <param-value>classpath:applcationContext.xml</param-value>
  8. </context-param>
        在src中引入applacationContext.xml;(约束)
        在src中引入log4j.properties;

    * 创建包结构:
       * action: action类;
       * service: 
       * domain: 实体 product
       * dao:
    * Struts2整合Spring框架:
  3.创建jsp页面
  1. <%@ page language="java" contentType="text/html; charset=utf8"
  2. pageEncoding="utf8"%>
  3. <%@ taglib uri="/struts-tags" prefix="s"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf8">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <h1>保存商品的页面</h1>
  12. <s:form action = "" method="post" namespace="/" theme="simlpe">
  13. <table border="1" width="400">
  14. <tr>
  15. <td>商品名称</td>
  16. <td><s:textfield name = "pname"/></td>
  17. </tr>
  18. </table>
  19. <table>
  20. <tr>
  21. <td>商品价格</td>
  22. <td><s:textfield name = "price"/></td>
  23. </tr>
  24. </table>
  25. <table>
  26. <tr>
  27. <td colspan=2><input type = "submit" value = "提交"/></td>
  28. </tr>
  29. </table>
  30. </s:form>
  31. </body>
  32. </html>
4.创建编写Action、Service、Dao 类;

5.配置Action、Service、Dao 类;
    * Struts2和Spring整合的两种方式:
        1、Action的类由Struts2自身去创建
        2、Action的类交给Spring框架去创建
    * Service和Dao 须在 applactionContext.xml中进行配置















SSH整合

标签:htm   链接   service   技术分享   names   work   html 4.01   class   plugin   

原文地址:http://www.cnblogs.com/Jxiaobai/p/6618614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!