新浪旧事-webwork、webwork+spring和webwork+spring+hibernate

webwork:

 

jar包:

commons-logging.jar
freemarker.jar
javassist.jar
ognl.jar
oscore.jar
rife-continuations.jar
webwork-2.2.7.jar
xwork.jar

 

web.xml中添加:

[java]  view plain  copy
  1. <filter>  
  2.     <filter-name>webwork</filter-name>  
  3.     <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>  
  4. </filter>  
  5. <filter-mapping>  
  6.     <filter-name>webwork</filter-name>  
  7.     <url-pattern>/*</url-pattern>  
  8. </filter-mapping>  

src/xwork.xml内容的第一行:

[java]  view plain  copy
  1. <include file="webwork-default.xml" />  

webwork+spring:

 

jar包:

commons-logging.jar
freemarker.jar
javassist.jar
ognl.jar
oscore.jar
rife-continuations.jar
webwork-2.2.7.jar
xwork.jar
org.springframework.asm.jar
org.springframework.beans.jar
org.springframework.context.jar
org.springframework.core.jar
org.springframework.expression.jar
org.springframework.web.jar

 

web.xml中添加:

[java]  view plain  copy
  1. <listener>  
  2.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  3. </listener>  
  4.    
  5. <filter>  
  6.     <filter-name>webwork</filter-name>  
  7.     <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>  
  8. </filter>  
  9.    
  10. <filter-mapping>  
  11.     <filter-name>webwork</filter-name>  
  12.     <url-pattern>/*</url-pattern>  
  13. </filter-mapping>  
  14.    
  15. <context-param>  
  16.     <param-name>contextConfigLocation</param-name>  
  17.     <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>  
  18. </context-param>  

注意:context-param要灵活配置,contextConfigLocation指明了spring的配置文件的位置和文件名。

 

假设的applicationContext-bean.xml:

[java]  view plain  copy
  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.        xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">  
  5.     <bean id="userDao" class="dao.impl.UserDaoImpl">  
  6.     </bean>  
  7.    
  8. </beans>  

假设的applicationContext-action.xml:

[java]  view plain  copy
  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.        xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">  
  5.     <bean id="registerAction" class="action.RegisterAction">  
  6.         <property name="userDao" ref="userDao"></property>  
  7.     </bean>   
  8. </beans>  

假设的xwork.xml:

[java]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">  
  3. <xwork>  
  4.     <include file="webwork-default.xml" />  
  5.    
  6.     <package name="webwork" extends="webwork-default">  
  7.         <action name="register" class="registerAction">  
  8.             <result name="success">/success.jsp</result>  
  9.         </action>  
  10.     </package>  
  11. </xwork>  

千万记得,一定要有的一个文件——src/webwork.properties:

[java]  view plain  copy
  1. webwork.objectFactory=spring  
  2. webwork.objectFactory.spring.autoWire=true  

webwork+spring+hibernate:

jar包:

commons-logging.jar
freemarker.jar
javassist.jar
ognl.jar
oscore.jar
rife-continuations.jar
webwork-2.2.7.jar
xwork.jar
org.springframework.asm.jar
org.springframework.beans.jar
org.springframework.context.jar
org.springframework.core.jar
org.springframework.expression.jar
org.springframework.web.jar
aopalliance.jar
aspectjweaver.jar
commons-collections.jar
dom4j.jar
hibernate3.jar
jta.jar
log4j.jar
mysql-connector-java.jar
org.springframework.aop.jar
org.springframework.jdbc.jar
org.springframework.orm.jar
org.springframework.transaction.jar
slf4j-api.jar
slf4j-log4j12.jar

 

web.xml在webwork+spring的基础上,再加上:

[java]  view plain  copy
  1. <filter>  
  2.     <filter-name>hibernateFilter</filter-name>  
  3.     <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>  
  4. </filter>  
  5. <filter-mapping>  
  6.     <filter-name>hibernateFilter</filter-name>  
  7.     <url-pattern>/*</url-pattern>  
  8. </filter-mapping>  


applicationContext-bean.xml和applicationContext-action.xml的使用方法不变,在这个基础上,加一个文件——applicationContext-common.xml:

[java]  view plain  copy
  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" xmlns:aop="http://www.springframework.org/schema/aop"  
  4.  xmlns:tx="http://www.springframework.org/schema/tx"  
  5.  xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
  6.      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd  
  7.      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">  
  8.    
  9.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  10.         <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>  
  11.     </bean>  
  12.    
  13.     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  14.         <property name="sessionFactory" ref="sessionFactory"></property>  
  15.     </bean>  
  16.    
  17.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  18.         <tx:attributes>  
  19.             <tx:method name="create*" propagation="REQUIRED"/>  
  20.             <tx:method name="delete*" propagation="REQUIRED"/>  
  21.             <tx:method name="update*" propagation="REQUIRED"/>  
  22.             <tx:method name="read*" propagation="REQUIRED"/>  
  23.             <tx:method name="list*" propagation="REQUIRED"/>  
  24.             <tx:method name="*" read-only="true"/>  
  25.         </tx:attributes>  
  26.     </tx:advice>  
  27.    
  28.     <aop:config>  
  29.         <aop:pointcut expression="execution(* dao.*.*(..))" id="allManagerMethod"/>  
  30.         <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>  
  31.     </aop:config>  
  32. </beans>  

其他文件,例如xwork.xml、webwork.properties等文件使用方法不变,在此基础上加上log4j.properties、hibernate.cfg.xml、User.hbm.xml等,即可使用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值