ylrainbow 2009-06-22 15:28
浏览 310
已采纳

SSH框架 session问题

我用的strut2 spring2 hibernate3 做了个小列子..struts.xml配置如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">



/list.jsp

    <action name="delTUser" class="delTUserAction">
        <result type="redirect">/list.action</result>
    </action>               

</package>

问题:
我点击删除user1 它会redirect 到list.action这上面来,,但是它还会出现user1这条记录,,再刷新后就没了..

这有什么解决方法吗? 流程是不变的,,
[b]问题补充:[/b]
很传统的写法
DAO 继承HibernateDaoSupport 用getHibernateTemplate().delete(user);删除
spring 的配置如下

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/demo/model/TUser.hbm.xml</value>
    <value>com/demo/model/TProduct.hbm.xml</value>
    </list>
    </property>
    </bean>
-->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation"
        value="classpath:hibernate.cfg.xml">
    </property>
</bean>

<bean id="TUserDAO" class="com.demo.dao.impl.TUserDAOImpl"
    scope="singleton">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>


<bean id="TUserService"
    class="com.demo.service.impl.TUserServiceImpl">
    <property name="userdao">
        <ref bean="TUserDAO" />
    </property>
</bean>


<bean id="listUserAction"
    class="com.demo.action.user.ListUserAction" scope="prototype">
    <property name="service">
        <ref bean="TUserService" />
    </property>
</bean>


<bean id="delTUserAction"
    class="com.demo.action.user.delTUserAction" scope="prototype">
    <property name="service">
        <ref bean="TUserService" />
    </property>
</bean>

transactionManager

<?xml version="1.0" encoding="UTF-8"?>
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">

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

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="del*" propagation="REQUIRED" />
        <tx:method name="modify*" propagation="REQUIRED" />
        <tx:method name="*" read-only="true" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="allManagerMethod" expression="execution(* com.demo.*.*.*(..))"/>
    <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>

[b]问题补充:[/b]
我用到了hibernate的延时加载..是web.xml里面设置的


contextConfigLocation
/WEB-INF/applicationContext*.xml

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<filter>
    <filter-name>opensession</filter-name>
    <filter-class>
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
</filter>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>opensession</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

[b]问题补充:[/b]
我加了getHibernateTemplate().flush(); 问题依然存在...很多SSH项目种都加这种延时,那么他们是怎么解决的呢..

  • 写回答

4条回答

  • 马勒格彼得 2009-06-22 15:55
    关注

    貌似是缓存的问题吧



    把这三条语句加在页面的

    里面就可以了
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!