• SSH整合


    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中进行配置















  • 相关阅读:
    java 字节流与字符流的区别
    什么是缓冲区
    java流输入输出
    Apache安装配置
    Maven学习
    Redis
    数据结构与算法
    pig ERROR 2997: Encountered IOException. File or directory null does not exist.
    hadoop学习路线(转)
    86标准SQL与92标准SQL用法区别
  • 原文地址:https://www.cnblogs.com/Jxiaobai/p/6618614.html
Copyright © 2020-2023  润新知