SSH整合——OpenSessionInViewFilter

来源:互联网 发布:淘宝验证码 编辑:程序博客网 时间:2024/06/03 15:04

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前面

原创粉丝点击