SSH配置文件

SSH整合有多种方式,我的方式:

 

把所有配置文件放到一个Config目录下。

 

Hibernate配置文件:

 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
 <property name="dialect">
  org.hibernate.dialect.MySQLDialect
 </property>
 <property name="connection.url">
  jdbc:mysql://localhost:3306/test
 </property>
 <property name="connection.username">root</property>
 <property name="connection.password">root</property>
 <property name="connection.driver_class">
  com.mysql.jdbc.Driver
 </property>
 <property name="myeclipse.connection.profile">mysql</property>
 <property name="show_sql">true</property>
 <property name="jdbc.fetch_size">50</property>
 <property name="jdbc.batch_size">30</property>
 <property name="hbm2ddl.auto">update</property>
 <property name="current_session_context_class">thread</property>

 <!-- 加入映射文件-->
</session-factory>

</hibernate-configuration>

 

Spring配置文件:

<?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: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-2.0.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation"
   value="classpath:hibernate/hibernate.cfg.xml">
  </property>
 </bean>
 
 <!-- 事务配置开始 -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref local="sessionFactory"/>
  </property>
 </bean>
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="add*" propagation="REQUIRED"/>
   <tx:method name="save*" propagation="REQUIRED"/>
   <tx:method name="del*" propagation="REQUIRED"/>
   <tx:method name="update*" propagation="REQUIRED"/>
   <tx:method name="*" read-only="true"/>
  </tx:attributes>
 </tx:advice>
 
 <aop:config>
  <aop:pointcut id="allManagerMethod" expression="execution (* <!--自定义-->*.*(..))"/>
  <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
 </aop:config>
 <!-- 事务配置结束 -->
 
 <!-- bean配置开始 -->


  <!-- bean配置开始 -->
 <!-- Struts配置开始 -->


  <!-- Struts配置结束 -->
</beans>

 

Struts配置文件:

 

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

<struts-config>
  <data-sources />
  <form-beans>
   <form-bean name="orgForm" type="com.derek.oa.web.form.OrgForm"/>
  </form-beans>
  <global-exceptions>
    </global-exceptions>
  <global-forwards>
  </global-forwards>
  <action-mappings>
   <action path="/orgAction"
    name="orgForm"
    type="org.springframework.web.struts.DelegatingActionProxy"
    input="/orgnization/index.jsp"
    parameter="method">
    <forward name="index" path="/orgnization/index.jsp" redirect="false"/>
    </action>
  </action-mappings>
  <message-resources parameter="struts.ApplicationResources" />
</struts-config>

注意:org.springframework.web.struts.DelegatingActionProxy

而且不能配置plugin

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
   <set-property property="contextConfigLocation" value="classpath:spring/*.xml"/>
  </plug-in>

 

 

web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
  <!-- Struts配置 -->
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/classes/struts/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
 
  <!-- Spring配置 -->
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:spring/*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
 
  <!-- OpenSession过滤器 -->
  <filter>
   <filter-name>opensession</filter-name>
   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>opensession</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
 
  <!-- 字符过滤器 -->
  <filter>
   <filter-name>characterfilter</filter-name>
   <filter-class>com.derek.oa.util.filter.SetCharacterEncodingFilter</filter-class>
   <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
   </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterfilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
 
  <!-- 首页 -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
  <!-- 标签配置 -->
  <jsp-config>
   <taglib>
    <taglib-uri>/tags/struts-html</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
   </taglib>
   <taglib>
    <taglib-uri>/tags/struts-bean</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
   </taglib>
   <taglib>
    <taglib-uri>/tags/struts-logic</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
   </taglib>
   <taglib>
    <taglib-uri>/tags/struts-nested</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
   </taglib>
   <taglib>
    <taglib-uri>/tags/struts-tiles</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
   </taglib>
  </jsp-config>
</web-app>

 

sping2+struts1x+hibernate3成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值