FileDocCategorySizeDatePackage
JndiFilter.javaAPI DocExample1585Sun Aug 17 09:24:28 BST 2003com.jspservletcookbook

JndiFilter

public class JndiFilter extends Object implements Filter

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

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)

      
      javax.mail.Session mailSession = null;
 
       try {
        
           mailSession = (javax.mail.Session) env.lookup("MyEmail");
            
       } catch (NamingException ne) { }
        
       HttpServletRequest hRequest = null;
        
            
       if (request instanceof HttpServletRequest){

          hRequest = (HttpServletRequest) request;
                 
          HttpSession hSession = hRequest.getSession();
            
          if (hSession != null)
              hSession.setAttribute("MyEmail",mailSession);

       }//if
        
       chain.doFilter(request,response);

  
public voidinit(javax.servlet.FilterConfig filterConfig)

    
     this.config = filterConfig;
      
     try {
           
         env = (Context) new InitialContext();
             
      } catch (NamingException ne) { 

          throw new ServletException(ne);

     }