webwork、webwork+spring和webwork+spring+hibernate

news/2024/7/20 2:42:47 标签: webwork, spring, hibernate, encoding, attributes, aop

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中添加:

<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


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

<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中添加:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 
<filter>
    <filter-name>webwork</filter-name>
    <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
 
<filter-mapping>
    <filter-name>webwork</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
 
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>


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

 

假设的applicationContext-bean.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="userDao" class="dao.impl.UserDaoImpl">
    </bean>
 
</beans>


假设的applicationContext-action.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="registerAction" class="action.RegisterAction">
        <property name="userDao" ref="userDao"></property>
    </bean> 
</beans>


假设的xwork.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
    <include file="webwork-default.xml" />
 
    <package name="webwork" extends="webwork-default">
        <action name="register" class="registerAction">
            <result name="success">/success.jsp</result>
        </action>
    </package>
</xwork>


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

webwork.objectFactory=spring
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的基础上,再加上:

<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>
</filter-mapping>

applicationContext-bean.xml和applicationContext-action.xml的使用方法不变,在这个基础上,加一个文件——applicationContext-common.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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://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.cfg.xml"></property>
    </bean>
 
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
 
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="create*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="read*" propagation="REQUIRED"/>
            <tx:method name="list*" propagation="REQUIRED"/>
            <tx:method name="*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <aop:pointcut expression="execution(* dao.*.*(..))" id="allManagerMethod"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>
</beans>


其他文件,例如xwork.xml、webwork.properties等文件使用方法不变,在此基础上加上log4j.properties、hibernate.cfg.xml、User.hbm.xml等,即可使用。


http://www.niftyadmin.cn/n/1262943.html

相关文章

PostgreSQL执行器性能(一)

以下是我在阅读执行器说明的一些内容&#xff0c;我想这对于阅读执行器的源代码还是有所帮助的。如果有什么写的不对的&#xff0c;请大家提出来帮忙修改一下。&#xff08;主要来源于源代码说明&#xff09;执行器处理的是一棵“规划节点”树。该规划树本质上是一个需求拉动的…

haproxy 代理mysql_配置Haproxy代理实现MySQL从服务器的负载均衡

之前的文章配置过haproxy以及简单使用&#xff0c;具体可以参考《Centos系统环境下进行负载均衡软件Haproxy安装及配置》&#xff0c; 今天文章记录下通过配置Haproxy代理实现MySQL从服务器的负载均衡。haproxy本身支持TCP协议的负载均衡转发&#xff0c;对于各种基于tcp的软件…

MyEclipse8.5安装svn

注&#xff1a;在Myeclipse8.6中可以直接在注册中心添加 一、下载svn&#xff1a;http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID2240 二、将site-1.6.12.zip解压&#xff0c;全部放入%MyEclipse安装目录%\Genuitec\MyEclipse 8.5\dropins文件夹下。 三、…

Silverpath 我的Silverlight开发心得 [1] 动态加载XAP时出现的致命错误

有哪些朋友现在在用Silverlight程序引导启动另一个Silverlight&#xff1f;如果你是其中的一员&#xff0c;你可能难免碰到了如下的诡异问题。如果你不是&#xff0c;也许你会在读完本文后放下js xaml的Loader...改用Silverlight做引导 :) 首先简单说一下背景&#xff0c;最近…

thankphp 3.2 mysql链接数据库_thinkphp3.2同时连接两个数据库的简单方法

因项目需求,需要用到连接两个库,所以封装了个方法,实例如下&#xff1a;在公共的function.php加入封装的方法function getCrmModel($name){// new的model可以根据自己的需求去更改return new \Home\Model\CrmModel($name);}model代码namespace Home\Model;class CrmModel exten…

svn服务端配置及在MyEclipse中的使用

首先&#xff0c;在http://subversion.tigris.org/servlets/ProjectDocumentList?folderID11129&expandFolder11129&folderID91&#xff08;现在是http://subversion.apache.org/packages.html&#xff09;上下载Setup-Subversion-1.6.6.msi&#xff0c; 在http://tor…

vs2003开发中的一些问题

一。已检测到指定的web服务器运行的不是asp.net1.1版本&#xff0c; 您将无法运行asp.net应用程序 这个问题有些人把问题归咎在先装了vs2005然后又装了vs2003其实不然&#xff0c;建议从以下几个方面检查一下&#xff1a; 1.是否IIS&#xff0c;如果没有请安装IIS&#xff0…

android arrays.xml 二维数组,Solidity语法--- 数组 (Arrays)

学习目标掌握Arrays的可变不可变的创建深度理解可变数组和不可变数组之间的区别二位数组memory arrays的创建bytes0 &#xff5e; bytes32、bytes与byte[]对比固定长度的数组(Arrays)固定长度类型数组的声明pragma solidity ^0.4.4;contract C {// 数组的长度为5&#xff0c;数…