【发布时间】:2011-10-15 17:32:55
【问题描述】:
我正在使用 Hibernate 和 jsp 编写一个博客系统。 我想使用过滤器来管理会话和事务。现在我写一个过滤器:
public class SessionFilter implements Filter {
FilterConfig config;
SessionFactory sessionFactory;
Session session;
public void destroy() {
session.getTransaction().commit();
this.config=null;
System.out.println("session Filter is destroyed.");
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
sessionFactory = (SessionFactory) config.getServletContext().getAttribute("sessionFactory");
session = sessionFactory.getCurrentSession();
session.beginTransaction();
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
this.config=config;
System.out.println("session Filter is inited.");
}
}
现在结果是我的表单字段没有保存到 mysql 。
【问题讨论】:
标签: java hibernate jsp servlets servlet-filters