SSH2的整合

 

利用 MyEclipse 进行 S2SH 整合

 

软件:jdk1.6 MyEclise6.5 Struts2.0.11 Spring2.0 hibernate3.2 Tomcat6.0

 

 

第一步 ,新建 web 项目

 

 

第二步 加入 spring2.0 的支持,加入jar包:

 

       spring 2.0 AOP library

       spring 2.0 core library

       spring 2.0 Persistence Core library // 对持久化倒支持

       spring 2.0 Persistence JDBC library // 对持久化倒支持

       spring 2.0 WEB JDBC library

 

 

第三步 给项目加入 hibernate 支持,利用 spring 管理 hibernate

 

 

第四步 增加 struts2 的支持

 

 

增加 struts jar 文件

       ognl.jar ,

       strtus2-core.jar ,

       freemarker.jar ,

       xwork.jar

       struts2-spring-plugin.jar

       还有一个 commons-logging.jar, 已经由整合 spring 的时候已经加入

 

 

src 中加入 struts.xml ,加入DTD标示

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

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

</struts>

 

 

修改 web.xml ,加入 spring 的监听器 (Listener)

       <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                        /WEB-INF/classes/applicationContext-*.xml
                </param-value>
                <!--  
                        <param-value>classpath*:applicationContext-*.xml</param-value>
                -->
        </context-param>

        <listener>
                <listener-class>
                        org.springframework.web.context.ContextLoaderListener
                </listener-class>
        </listener>

 

修改 web.xml ,加入 struts2 的过滤器 (filter)

<display-name>Struts Blank</display-name>
<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

 

修改 web.xml ,加入 hibernate session load 处理

<!-- Spring 为我们自动地进行Hibernate Session管理 -->
<filter>
  <filter-name>hibernateFilter</filter-name>
  <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  </filter-class>
</filter>
<filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <!--  
       <url-pattern>*.action</url-pattern> 
    -->
</filter-mapping>

 

修改 web.xml ,加入中文处理

<!-- Spring 进行 中文编码 -->
<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
    <filter-mapping>
      <filter-name>encodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
</filter-mapping>

 

第五步 ,修改 applicationContext.xml ,完善 spring hibernate 的支持

<?xml version="1.0" encoding="UTF-8"?>
<beans
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
			
       <!-- 配置数据源 -->
       <!-- 一下分别配置了 数据库驱动 数据库路径 用户名 密码等 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
			<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
			<property name="url" value="jdbc:mysql://localhost:3306/mytest"></property>
			<property name="username" value="root"></property>
			<property name="password" value="123456"></property>
			<property name="maxActive" value="100"></property>
			<property name="maxIdle" value="30"></property>
			<property name="maxWait" value="500"></property>
			<property name="defaultAutoCommit" value="true"></property>
	</bean>		
    
       <!-- 一下配置sessionFactory  这个东西曾经是在hibernate中定义的 如今交给了spring管理 -->
       <bean id="sessionFactory" 
                  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource"></property>
   			<property name="hibernateProperties">
				<props>
					<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
					<prop key="hibernate.show_sql">true</prop>
				</props>
   			</property>
   			<property name="mappingResources">
   					<list>
   						<value>com/test/bean/User.hbm.xml</value>
   					</list>
   			</property>	
       </bean>
    
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值