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个回答

貌似是缓存的问题吧



把这三条语句加在页面的

里面就可以了

你的删除user的代码应该写得有些问题吧

导致没有马上提交删除事务

LZ,你在删除记录后加上刷新方法吧
比如:
getHibernateTemplate().flush();

session.flush();

你的DAO 继承HibernateDaoSupport 用getHibernateTemplate().delete(user);
这段代码部分后面加上getHibernateTemplate().flush();
因为你用了OpenSessionInViewFilter这种方式,导致web端session还没有进行提交事务

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐