• java实现遍历树形菜单方法——OpenSessionView实现


     /**  
    * @Title: OpenSessionView.java
    * @Package org.util
    * @Description: TODO该方法的主要作用:
    * @author A18ccms A18ccms_gmail_com  
    * @date 2017-5-6 下午1:48:25
    * @version V1.0  
    */
    package org.web;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    
    import org.dao.BaseHibernateDao;
    import org.hibernate.Hibernate;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    
     /**   
     *    
     * 项目名称:votedemo   
     * 类名称:OpenSessionView   
     * 类描述:   让session 始终保持着一个打开的状态
     * 创建人:Mu Xiongxiong  
     * 创建时间:2017-5-6 下午1:48:25   
     * 修改人:Mu Xiongxiong   
     * 修改时间:2017-5-6 下午1:48:25   
     * 修改备注:   
     * @version    
     *    
     */
    public class OpenSessionView extends BaseHibernateDao implements Filter {
    
    	/**(非 Javadoc)
    	 * <p>Title: destroy</p>
    	 * <p>Description(描述): </p>
    	 * @see javax.servlet.Filter#destroy()
    	 */
    
    	@Override
    	public void destroy() {
    		// TODO Auto-generated method stub
    
    	}
    
    	/**(非 Javadoc)
    	 * <p>Title: doFilter</p>
    	 * <p>Description(描述): </p>
    	 * @param arg0
    	 * @param arg1
    	 * @param arg2
    	 * @throws IOException
    	 * @throws ServletException
    	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
    	 */
    
    	@Override
    	public void doFilter(ServletRequest arg0, ServletResponse arg1,
    			FilterChain arg2) throws IOException, ServletException {
    		Session session = null;
    		Transaction tx  = null;
    		
    		try {
    			session = getSession();
    			tx = session.beginTransaction();
    			arg2.doFilter(arg0, arg1);
    			tx.commit();
    		} catch (Exception e) {
    			e.printStackTrace();
    			tx.rollback();
    		}finally{
    			closeSession();
    		}
    		
    
    	}
    
    	/**(非 Javadoc)
    	 * <p>Title: init</p>
    	 * <p>Description(描述): </p>
    	 * @param arg0
    	 * @throws ServletException
    	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
    	 */
    
    	@Override
    	public void init(FilterConfig arg0) throws ServletException {
    		// TODO Auto-generated method stub
    
    	}
    
    }
    

  • 相关阅读:
    windows的一组常用运行命令
    nfs:server is not responding,still trying 原因与解决方案
    MYSQL外键(Foreign Key)的使用
    byte[]转字符串编码问题
    /usr/bin/ld: cannot find lGL
    Linux查看用户及分组
    NAND和NOR flash的区别
    Win7+Ubuntu11.10(EasyBCD硬盘安装)
    Win7+Ubuntu12.04.1硬盘安装错误及解决方案
    Linux内核编译时错误
  • 原文地址:https://www.cnblogs.com/a1111/p/12816270.html
Copyright © 2020-2023  润新知