SSH框架的搭建

来源:互联网 发布:2017网络视听大会 编辑:程序博客网 时间:2024/05/16 18:23

           近几天搜了一下关于ssh框架搭建的文章,发现大多都是反向生成相关配置文件,添加jar包的方式也不够清晰,于是想自己写下自己搭建框架的方法。

           

          SSH框架搭建:

          1.创建一个web工程。

          2.引入jar包和相关文件配置。

             Struts2:       

* jar包:struts-2.3.15.3\apps\struts2-blank.war\WEB-INF\lib\*.jarstruts-2.3.15.3\lib\struts2-json-plugin-2.3.15.3.jarstruts-2.3.15.3\lib\struts2-spring-plugin-2.3.15.3.jar* 配置文件:* 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>* struts.xml
            Spring:

* jar包:Spring3.2 开发最基本jar包spring-beans-3.2.0.RELEASE.jarspring-context-3.2.0.RELEASE.jarspring-core-3.2.0.RELEASE.jarspring-expression-3.2.0.RELEASE.jarcom.springsource.org.apache.commons.logging-1.1.1.jarcom.springsource.org.apache.log4j-1.2.15.jarAOP开发spring-aop-3.2.0.RELEASE.jarspring-aspects-3.2.0.RELEASE.jarcom.springsource.org.aopalliance-1.0.0.jarcom.springsource.org.aspectj.weaver-1.6.8.RELEASE.jarSpring Jdbc开发spring-jdbc-3.2.0.RELEASE.jarspring-tx-3.2.0.RELEASE.jarSpring事务管理spring-tx-3.2.0.RELEASE.jarSpring整合其他ORM框架spring-orm-3.2.0.RELEASE.jarSpring在web中使用spring-web-3.2.0.RELEASE.jarSpring整合Junit测试spring-test-3.2.0.RELEASE.jar* 配置文件:* 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>* applicationContext.xml* log4j.properties
           Hibernate:

* jar包:* hibernate-distribution-3.6.10.Final\hibernate3.jar* hibernate-distribution-3.6.10.Final\lib\required\*.jar* hibernate-distribution-3.6.10.Final\lib\jpa\*.jar* slf4j-log4j整合的jar包 :* 数据库驱动:* 连接池:(c3p0连接池)* 配置文件:* 没有hibernate的核心配置文件的方式整合:* 映射文件:3.配置基本配置信息:* C3P0连接池:* 引入外部属性文件:* jdbc.properties* 配置连接池:<!-- 配置连接池: --><!-- 引入外部属性文件 --><context:property-placeholder location="classpath:jdbc.properties"/><!-- 配置C3P0连接池: --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/><property name="user" value="${jdbc.user}"/><property name="password" value="${jdbc.password}"/></bean>* Hibernate相关信息:<!-- Hibernate的相关信息 --><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!-- 注入连接池 --><property name="dataSource" ref="dataSource"/><!-- 配置Hibernate的其他的属性 --><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.connection.autocommit">false</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><!-- 配置Hibernate的映射文件 --></bean>
               事物管理:

<!-- 事务管理: --><!-- 事务管理器 --><bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"/></bean><!-- 开启注解事务 --><tx:annotation-driven transaction-manager="transactionManager"/>

            3.配置action和访问首页jsp文件

  

1.编写Action:* IndexAction2.配置Action* 配置applicationContext.xml<!-- 首页访问的Action --><bean id="indexAction" class="cn.itcast.shop.index.action.IndexAction" scope="prototype"></bean>* 配置struts.xml<!-- 配置首页访问的Action --><action name="index" class="indexAction"><result name="index">/WEB-INF/jsp/index.jsp</result></action>



             


1 0
原创粉丝点击