您的位置:首页 > 运维架构

SSH整合——OpenSessionInViewFilter

2017-07-24 18:17 239 查看
getCurrentSession()事务会自动关闭,所以在所有jsp页面查询数据都会关闭session。要想在jsp查询数据库需要加入OpenSessionInViewFilter过滤器。

session通常随着事物开始而打开,事物结束而关闭,因此在jsp页面调用数据库时会出现No Session found for current thread错误。

openSessionInView的作用就是扩大事物的边界,由它来控制session的关闭



openSessionInView的配置

web.xml

<!-- openSessionInView过滤器 -->
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


*openSessionInViewFilter要放在Struts2Filter前面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: