What are the methods of Filter Interface?


1. public void init(FilterConfig filterConfig)throws ServletException

2.  public void doFilter(ServletRequest request,

                     ServletResponse response,

                     FilterChain chain)

              throws java.io.IOException,

                     ServletException

3.  public void destroy()

servlet cookies in java


javax.servlet.http
Class Cookie

public class Cookie

                         extends java.lang.Object

                         implements java.lang.Cloneable

cookies are a small amount of information sent by a servlet to a Web browser,saved by the browser, and later sent back to the server. A cookie’s value can uniquely identify a client, so cookies are commonly used for session management.

A cookie contain  a name, and a value.

The browser is expected to support 20 cookies.

The cookie size is 4 KB.

The cookie contains only one constructor 

public Cookie(java.lang.String name, java.lang.String value)
some of the methods of cookies are

public void setComment(java.lang.String purpose)

public java.lang.String getComment()

public void setDomain(java.lang.String pattern)

public java.lang.String getDomain()

public void setMaxAge(int expiry)

public int getMaxAge()

public void setPath(java.lang.String uri)

public java.lang.String getPath()

public void setSecure(boolean flag)

public boolean getSecure()

public java.lang.String getName()

public void setValue(java.lang.String newValue)

public java.lang.String getValue()

public int getVersion()

public void setVersion(int v)

public java.lang.Object clone()

ServletConfig


javax.servlet
Interface ServletConfig

public interface ServletConfig

ServletConfig is a servlet container object 

ServletConfig object is created at the time of application initialization

ServletConfig methos are show below 

1. public java.lang.String getServletName()

2.  public ServletContext getServletContext()

3.  public java.lang.String getInitParameter(java.lang.String name)

4.  public java.util.Enumeration getInitParameterNames()

   

explain about filters in servlets


javax.servlet
Interface Filter

Filter concept is introduced in Servlet 2.3

javax.servlet.Filter contains the following methods

1.   void init(FilterConfig filterConfig)

                        throws ServletException

2.  void doFilter(ServletRequest request,

                                  ServletResponse response,

                                 FilterChain chain)

              throws java.io.IOException,ServletException

3.  void destroy()

When will container destroy the Servlet?


–          Stop all the requests to this Servlet.

–          Wait till the existing request to this Servlet get complete.

–          Call the destroy() mehod of the Servlet After this the Servlet is no more there in the Container.

                    The Servlet is destroyed by the container following the above process only when the application is undeployed.