解决session关闭时再调用对象方法时报session已关闭问题
private SessionFactory sf;//filter -- > public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { // sf.getCurrentSession();//获得和当前线程绑定的session sf.getCurrentSession().beginTransaction(); chain.doFilter(request, response); sf.getCurrentSession().getTransaction().commit(); } catch (StaleObjectStateException staleEx) { throw staleEx; } catch (Throwable ex) { ex.printStackTrace(); try { if (sf.getCurrentSession().getTransaction().isActive()) { sf.getCurrentSession().getTransaction().rollback(); } } catch (Throwable rbEx) { } throw new ServletException(ex); } } public void init(FilterConfig filterConfig) throws ServletException { sf = HibernateSessionFactory.getSessionFactory(); } public void destroy() { }