OncePerRequestFilter Example:--
public class HibernateSessionFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
Session session = null;
try {
SessionFactory sf = lookupSessionFactory(request);
session = sf.openSession(new DateEntryInterceptor());
}
private SessionFactory lookupSessionFactory(HttpServletRequest request) {
SessionFactory sf = null;
sf = (SessionFactory) getContext(request).getBean("stagingSessionFactory");
return sf;
}
public ApplicationContext getContext(HttpServletRequest httpRequest) {
return WebApplicationContextUtils.getRequiredWebApplicationContext(httpRequest.getSession().getServletContext());
}
}
-- In Web.xml
ReplyDeleteHibernateSessionFilter
*.htm
REQUEST