what is the error you are getting. The code seems to be working fine except for the error in line where you have written SessionController. This code will work only if you are using servlet 2.3 and not with servlet2.2.
 
Regards,
Vikramjit Singh,
GTL Ltd.
Ph. 7612929-1059
-----Original Message-----
From: Les Parker [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 16, 2002 10:02 AM
To: [EMAIL PROTECTED]
Subject: Adding a cookie via a filterChain...

Can anyone tell me why this does not seem to work?
I am at a dead end and have been staring at it too long.
Thanks for your help...
 
public final class SessionControlFilter implements Filter
{
   private String attribute = null;
   private FilterConfig filterConfig = null;
   public void init(FilterConfig filterConfig) throws ServletException
   {
      this.filterConfig = filterConfig;
      this.attribute = filterConfig.getInitParameter("attribute");
      sessionController = SessionController.getInstance();
   }
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException
   {
      if (attribute != null) request.setAttribute(attribute, this);
      if(getCookie((HttpServletRequest)request, "CHOCLATE_CHIP") == null)
      {
        makeCookie((HttpServletResponse)response, "CHOCLATE_CHIP", "CLIENT", "666"); 
      }
      chain.doFilter(request, response);
   }
   public static Cookie getCookie(HttpServletRequest request, String name)
   {
      Cookie[] cookies = request.getCookies();
      Cookie myCookie = null;
      for (int i=0;i<cookies.length ;i++ )
      {
         if (cookies[i].getName().equals(name))
         {
            myCookie = cookies[i];
            break;
         }
      }
      return myCookie;
   }
   public void makeCookie(HttpServletResponse response, String name, String channel, String visitorId)   
   {
      String value = channel + "|" + visitorId;
      Cookie newCookie = new Cookie(name, value);
      newCookie.setPath("/");
      newCookie.setComment("No comment.");
      newCookie.setMaxAge(315360000);
      newCookie.setVersion(1);
      response.addCookie(newCookie);
   }
   public void destroy()
   {
       this.attribute = null;
       this.filterConfig = null;
   }
}
 
 

This electronic mail transmission may contain confidential information and is intended only for the person(s) named. Any use, copying or disclosure by any other person is strictly prohibited. If you have received this transmission in error, please notify the sender via e-mail.

Reply via email to