ssh


ssh_第1张图片
 
ssh_第2张图片
 
ssh_第3张图片
 
ssh_第4张图片
 
ssh_第5张图片
 SSH整合:

1.创建一个web工程:

2.引入jar包和配置文件:

* struts2:

* jar:

struts-2.3.15.3\apps\struts2-blank.war\WEB-INF\lib\*.jar

struts-2.3.15.3\lib\struts2-json-plugin-2.3.15.3.jar

struts-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.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.commons.logging-1.1.1.jar

com.springsource.org.apache.log4j-1.2.15.jar

AOP开发

spring-aop-3.2.0.RELEASE.jar

spring-aspects-3.2.0.RELEASE.jar

com.springsource.org.aopalliance-1.0.0.jar

com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

Spring Jdbc开发

spring-jdbc-3.2.0.RELEASE.jar

spring-tx-3.2.0.RELEASE.jar

Spring事务管理

spring-tx-3.2.0.RELEASE.jar

Spring整合其他ORM框架

spring-orm-3.2.0.RELEASE.jar

Springweb中使用

spring-web-3.2.0.RELEASE.jar

Spring整合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"/>

 

 

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">
 <!-- 配置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>
 
 <!-- 配置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>
  <display-name></display-name> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

struts.xml

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

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

 <package name="shop" extends="struts-default" namespace="/">
  <global-results>
   <result name="msg">/WEB-INF/jsp/msg.jsp</result>
  </global-results>
 
  <!-- 配置首页访问的Action -->
  <action name="index" class="indexAction">
   <result name="index">/WEB-INF/jsp/index.jsp</result>
  </action>
  
  <!-- 配置用户模块的Action -->
  <action name="user_*" class="userAction" method="{1}">
   <result name="registPage">/WEB-INF/jsp/regist.jsp</result>
   <result name="input">/WEB-INF/jsp/regist.jsp</result>
   <result name="loginPage">/WEB-INF/jsp/login.jsp</result>
   <result name="login">/WEB-INF/jsp/login.jsp</result>
   <result name="loginSuccess" type="redirectAction">index</result>
   <result name="quit" type="redirectAction">index</result>
   <result name="checkcodeFail">/WEB-INF/jsp/regist.jsp</result>
  </action>
  
  <!-- 验证码Action -->
  <action name="checkImg" class="checkImgAction"></action>
 </package>
</struts>

applicationContext.xml

 

<?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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd">
 
 <!-- 配置连接池: -->
 <!-- 引入外部属性文件 -->
 <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的相关信息 -->
 <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的映射文件 -->
  <property name="mappingResources">
   <list>
    <value>cn/itcast/shop/user/vo/User.hbm.xml</value>
   </list>
  </property>
 </bean>
 
 <!-- 事务管理: -->
 <!-- 事务管理器 -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
 
 <!-- 开启注解事务 -->
 <tx:annotation-driven transaction-manager="transactionManager"/>
 
 <!-- Action的配置 ===========================-->
 
 <!-- 首页访问的Action -->
 <bean id="indexAction" class="cn.itcast.shop.index.action.IndexAction" scope="prototype">
 
 </bean>
 
 <!-- 配置验证码Action -->
 <bean id="checkImgAction" class="cn.itcast.shop.user.action.CheckImgAction" scope="prototype">
  
 </bean>
 
 <!-- 用户模块的Action -->
 <bean id="userAction" class="cn.itcast.shop.user.action.UserAction" scope="prototype">
  <!-- 注入Service -->
  <property name="userService" ref="userService"/>
 </bean>
 
 
 <!-- Service的配置  ===========================-->
 <bean id="userService" class="cn.itcast.shop.user.service.UserService">
  <property name="userDao" ref="userDao"/>
 </bean>
 
 
 
 <!-- Dao的配置  ===========================-->
 <bean id="userDao" class="cn.itcast.shop.user.dao.UserDao">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
</beans>

lojf4j.pro....

 

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:/mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=info, stdout

 

jdbc.pro...

 

jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql:///shop
jdbc.user = root
jdbc.password =123

 

 

 

<!--EndFragment-->

你可能感兴趣的:(ssh)