struts+hibernate3的源程序

源代码在线查看: sessionfilter.java

软件大小: 8215 K
上传用户: Numb_pqc
关键词: hibernate struts 源程序
下载地址: 免注册下载 普通下载 VIP

相关代码

				package org.helpsoft;
				
				import java.io.*;
				import javax.servlet.*;
				import javax.servlet.http.*;
				import org.helpsoft.servicelocator.*;
				
				
				 /**
				  * Make sure that after every request, the database session is closed.
				  *
				 * @author  cao guangxin  Helpsoft corp.
				 * @site www.helpsoft.org or www.relationinfo.com
				 * mail:relationinfo@gmail.com
				 */
				public class SessionFilter implements Filter {
				    /**
				     * Unused.
				     */
				    public void init(FilterConfig config) {
				    }
				
				    /**
				     * Unused.
				     */
				    public void destroy() {
				    }
				
				    /**
				     * process the chain and close the database session.
				     *
				     * @param request the servlet request
				     * @param response the servlet response
				     * @param chain the chain
				     * @throws IOException
				     * @throws ServletException
				     */
				    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
				       try {
				          chain.doFilter(request, response);
				       }
				       finally {
				         try {
				             DatabaseSessionService service = (DatabaseSessionService) ServiceLocator.getService(ServiceLocator.DATABASE_SESSION_SERVICE);
				             service.close();
				          } catch (Exception e) {
				             e.printStackTrace();
				         }
				       }
				    }
				}
							

相关资源