s2sh框架整合

(1)Struts2.3

(2)Spring包

(3)Hibernate包

(1)导Struts2包

(2)配Struts2文件

新建struts.xml文件,默认在项目的src根目录

  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <!DOCTYPE struts PUBLIC       
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"       
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">      
  5. <struts>  
  6.     <!-- 将Action的创建交给spring来管理 -->    
  7.     <constant name="struts.objectFactory" value="spring" />    
  8.       
  9.     <!-- 更改struts2请求Action的后缀名,默认为action。若想去掉后缀,设为","即可   
  10.     <constant name="struts.action.extension" value=","></constant>  
  11.     -->    
  12.     <package namespace="/" name="struts2" extends="struts-default">    
  13.           
  14.         <!-- package中的标签必须按照如下顺序配置  
  15.         result-types,interceptors,default-interceptor-ref,default-action-ref,default-class-ref,global-results,global-exception-mappings,action*(就是所有的action放到最后)  
  16.         -->  
  17.         <!-- 自定义拦截器 ,如果有拦截器,必须放在package标签内的第一位-->  
  18.         <interceptors>  
  19.             <!-- 
  20.             <interceptor name="myInterceptor" class="自定义pojo类"></interceptor> 
  21.             -->  
  22.             <interceptor-stack name="myInterceptorStack">  
  23.                 <!--   
  24.                 <interceptor-ref name="myInterceptor"></interceptor-ref> 
  25.                 -->  
  26.                 <interceptor-ref name="defaultStack"></interceptor-ref>  
  27.             </interceptor-stack>  
  28.         </interceptors>    
  29.           
  30.         <global-results>  
  31.             <result></result>  
  32.         </global-results>  
  33.           
  34.     </package>  
  35.       
  36.     <!-- 包含的配置文件   
  37.     <include file="/configs/struts-user.xml"></include>  
  38.     -->  
  39. </struts>  

配置web.xml文件

  1. <filter>  
  2.         <filter-name>struts2</filter-name>    
  3.         <filter-class>    
  4.           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter    
  5.         </filter-class>  
  6.         <init-param>  
  7.             <param-name>configs</param-name>  
  8.             <!-- 默认位置  
  9.                 <param-value>struts.xml</param-value>  
  10.              -->  
  11.             <param-value>classpath:configs/struts.xml</param-value>  
  12.         </init-param>  
  13.     </filter>    
  14.     <filter-mapping>    
  15.         <filter-name>struts2</filter-name>    
  16.         <url-pattern>/*</url-pattern>    
  17. </filter-mapping>  

(1)导入Spring相关文件

(2)配置Spring

新建aplicationContext.xml文件,默认在项目的src根目录

  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <beans xmlns="http://www.springframework.org/schema/beans"    
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  4.     xmlns:aop="http://www.springframework.org/schema/aop"    
  5.     xmlns:tx="http://www.springframework.org/schema/tx"    
  6.     xsi:schemaLocation="    
  7.     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    
  8.     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd    
  9.     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">  
  10. </beans> 

配置web.xml文件

  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:configs/applicationContext*.xml</param-value>    
  8. </context-param>  



(1)导Hibernate包

(2)配置Hibernate

(1)Hibernate与Spring之间的整合

  1. <!-- datasource -->  
  2.     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  3.         <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
  4.         <property name="url" value="jdbc:mysql://localhost:3306/lfdcwtjxt?characterEncoding=UTF-8" />  
  5.         <property name="username" value="root" />  
  6.         <property name="password" value="root" />  
  7.     </bean>  
  8.     <!-- spring与hibernate整合   
  9.     spring来管理session的创建、打开和关闭  
  10.     -->  
  11.     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
  12.         <!--  通过配置文件的方式获取数据源,出现异常,未解决  
  13.         <property name="configLocation">  
  14.             <value>classpath:configs/hibernate.cfg.xml</value>  
  15.         </property>  
  16.         -->  
  17.         <property name="dataSource" ref="dataSource" />  
  18.     </bean>  
  19.     <!-- 定义事物管理器,并位事物管理器配置上述所定义的session-->  
  20.     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
  21.         <property name="sessionFactory">  
  22.             <ref bean="sessionFactory"/>  
  23.         </property>  
  24.     </bean>  
  25.     <!-- 对事物管理器进行设置  
  26.         表示对save、del、update开头的方法应用事物  
  27.      -->  
  28.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  29.         <tx:attributes>  
  30.             <tx:method name="save*" propagation="REQUIRED"/>  
  31.             <tx:method name="del*" propagation="REQUIRED"/>  
  32.             <tx:method name="update*" propagation="REQUIRED"/>  
  33.         </tx:attributes>  
  34.     </tx:advice>  

(2)整合Spring与Structs2


struts2.xml中添加:

  1. <action name="login" class="login">  
  2. <result name="success">/index.jsp</result>  
  3. </action>  
在applicationContext.xml中添加:

  1. <bean id="login" class="com.action.LoginAction">  
  2. </bean> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值