一个登录验证的例子,涉及到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

Feedback

# re: 最近学习webwork+spring+hibernate,自己学习过程中的一个例子 [未登录]  回复  更多评论   

2007-08-02 14:42 by daniel
webwork+spring+hibernate都是什么版本的,我试着把这个项目重新编译、部署,但没有成功,找不到webwork-portlet-default.xml文件

# re: 最近学习webwork+spring+hibernate,自己学习过程中的一个例子   回复  更多评论   

2007-08-06 10:25 by Hally
webwork 2.2.5 spring2.0 hibernate3

# re: 最近学习webwork+spring+hibernate,自己学习过程中的一个例子   回复  更多评论   

2008-06-19 15:47 by wulj
dd

只有注册用户登录后才能发表评论。


网站导航:
 

posts - 43, comments - 200, trackbacks - 0, articles - 2

Copyright © Hally