FileDocCategorySizeDatePackage
JndiTFilter.javaAPI DocExample1720Fri Aug 15 10:43:28 BST 2003com.jspservletcookbook

JndiTFilter

public class JndiTFilter extends Object implements Filter

Fields Summary
private FilterConfig
config
private Context
env
Constructors Summary
public JndiTFilter()

Methods Summary
public voiddestroy()

        /*called before the Filter instance is removed 
        from service by the web container*/
    
public voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)

      
        StockPriceBean spbean = null;
        
        try {
        
            spbean = (StockPriceBean) env.lookup("bean/pricebean");
            
        } catch (NamingException ne) { }
        
        HttpServletRequest hRequest = null;
        
            
        if (request instanceof HttpServletRequest)
            hRequest = (HttpServletRequest) request;
                 
        HttpSession hSession = hRequest.getSession();
            
        if (hSession != null)
            hSession.setAttribute("MyBean",spbean);
        
        
        chain.doFilter(request,response);

    
public voidinit(javax.servlet.FilterConfig filterConfig)

    
      this.config = filterConfig;
      
       try {
           
               env = (Context) new InitialContext().lookup("java:comp/env");
			   
			   env.close();
             
      } catch (NamingException ne) { 
        
          try{ env.close(); } catch (NamingException nex) {}

          throw new ServletException(ne);


        }