最近学习webwork+spring+hibernate,自己学习过程中的一个例子

一个登录验证的例子,涉及到webwork action配置,三者结合的配置,使用了webwork的拦截器。数据库是mysql

下面把主要的配置文件列一下。

xwork.xml

 

<? xml version="1.0" encoding="ISO-8859-1" ?>
<! DOCTYPE xwork PUBLIC
        "-//OpenSymphony Group//XWork 1.1.1//EN"
        "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd"
>
<!--
   Copyright (c) 2002-2006 by OpenSymphony
   All rights reserved.
-->
< xwork >
    
< include  file ="webwork-portlet-default.xml" />


    
< package  name ="default"  extends ="webwork-default" >    <!--  namespace="/secure" -->
        
< interceptors >
            
< interceptor  name ="isLogin"  class ="com.hallywang.interceptors.LogInterceptor" />

        
</ interceptors >
        
< action  name ="login"
                class
="login" >

            
< result  name ="success"  type ="chain" > list </ result >

            
< result  name ="loginfail"  type ="dispatcher" >
                
< param  name ="location" > /index.jsp </ param >
            
</ result >
            
< interceptor-ref  name ="params" />
            
< interceptor-ref  name ="model-driven" />
            
< interceptor-ref  name ="validationWorkflowStack" />
        
</ action >

        
< action  name ="list"
                class
="list" >
            
< result  name ="success"  type ="dispatcher" >
                
< param  name ="location" > /list.jsp </ param >
            
</ result >
            
< result  name ="noLogin"  type ="dispatcher" >
                
< param  name ="location" > /index.jsp </ param >
            
</ result >
            
< interceptor-ref  name ="isLogin" >
            
</ interceptor-ref >

        
</ action >
    
</ package >
    
< package  name ="test"  namespace ="/test"  extends ="webwork-default" >    <!--  namespace="/secure" -->
        
< action  name ="login2"
                class
="login2" >

            
< result  name ="success"  type ="chain" > list </ result >

            
< result  name ="loginfail"  type ="dispatcher" >
                
< param  name ="location" > /index.jsp </ param >
            
</ result >
            
< interceptor-ref  name ="params" />
            
< interceptor-ref  name ="model-driven" />
            
< interceptor-ref  name ="validationWorkflowStack" />
        
</ action >


    
</ package >
</ xwork >

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"

       default-autowire
="byName"  default-lazy-init ="true" >
  
< aop:aspectj-autoproxy />

    
<!--  配置 dataSource   -->
    
<!--  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost/test</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>840301</value>
        </property>
    </bean>
-->
    
< bean  id ="dataSource"
          class
="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method
="close" >
        
< property  name ="driverClass" >
            
< value > com.mysql.jdbc.Driver </ value >
        
</ property >
        
< property  name ="jdbcUrl" >
            
< value > jdbc:mysql://localhost/test </ value >
        
</ property >
        
< property  name ="user" >
            
< value > root </ value >
        
</ property >
        
< property  name ="password" >
            
< value > root </ value >
        
</ property >
    
</ bean >


    
< bean  id ="hibernateProperties"
          class
="org.springframework.beans.factory.config.PropertiesFactoryBean" >
        
< property  name ="properties" >
            
< props >
                
< prop  key ="hibernate.dialect" >
                    org.hibernate.dialect.MySQLDialect
                
</ prop >
                
< prop  key ="hibernate.show_sql" >
                    true
                
</ prop >
                
< prop  key ="hibernate.format_sql" > false </ prop >
                
< prop  key ="hibernate.use_sql_comments" > false </ prop >

                
< prop  key ="hibernate.c3p0.testConnectionOnCheckout" >
                    false
                
</ prop >
                
< prop  key ="hibernate.c3p0.idle_test_period" > 100 </ prop >
                
< prop  key ="c3p0.testConnectionOnCheckout" > true </ prop >
                
< prop  key ="c3p0.minPoolSize" > 10 </ prop >
                
< prop  key ="hc3p0.maxPoolSize" > 50 </ prop >
                
< prop  key ="hc3p0.timeout" > 600 </ prop >
                
< prop  key ="c3p0.max_statement" > 50 </ prop >
                
< prop  key ="hibernate.c3p0.acquire_increment" > 1 </ prop >
                
< prop  key ="hibernate.c3p0.idle_test_period" > 100 </ prop >

            
</ props >
        
</ property >
    
</ bean >


    
<!--  配置sessionFactory   -->
    
< bean  id ="sessionFactory"  class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
        
< property  name ="dataSource" >
            
< ref  local ="dataSource" />
        
</ property >
        
< property  name ="mappingResources" >
            
< list >
                
< value > com/hallywang/po/User.hbm.xml </ value >
            
</ list >
        
</ property >
        
< property  name ="hibernateProperties" >
            
< ref  local ="hibernateProperties" />
        
</ property >
    
</ bean >

    
< bean  id ="transactionManager"  class ="org.springframework.orm.hibernate3.HibernateTransactionManager" >
        
< property  name ="sessionFactory" >
            
< ref  local ="sessionFactory" />
        
</ property >
    
</ bean >

    
< bean  id ="userDao"  class ="com.hallywang.dao.impl.UserDaoImpl"  scope ="prototype" >     <!-- scope="prototype" -->
        
< property  name ="sessionFactory" >
            
< ref  local ="sessionFactory" />
        
</ property >
    
</ bean >
    
< bean  id ="login"  class ="com.hallywang.action.LoginAction"  scope ="prototype" >
        
< property  name ="userDao" >
            
< ref  local ="userDao" />
        
</ property >
    
</ bean >
    
< bean  id ="list"  class ="com.hallywang.action.ListAction"  scope ="prototype" >
        
< property  name ="userDao" >
            
< ref  local ="userDao" />
        
</ property >
    
</ bean >

    
< bean  id ="login2"  class ="com.hallywang.action.Login2Action"  scope ="prototype" >
        
< property  name ="userDao" >
            
< ref  local ="userDao" />
        
</ property >
    
</ bean >


    
<!--  ****************************** AOP TEST ************************** -->

<!--

    <bean id="myAspect" class="com.hallywang.interceptors.MethodAspect">

    </bean>


     <bean id="test" class = "com.hallywang.Test"/>
-->


</ beans >

废话不多说,源代码传上来。

http://dl2.csdn.net/down4/20070719/19173314157.rar

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值