It's not a secret anymore!*
The moose likes Servlets and the fly likes filter objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "filter objects" Watch "filter objects" New topic
Author

filter objects

Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 231
hi guys

is filter objects are created for every new request

or created once for every new session

is their any way to control or it should create for every new request

or for every new session

looking for your replies
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Maybe this article will help you with your questions

Filters


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Filters are just a compliment to Servlet. You can take it as a special kind of servlet that can transform a request or modify a response.

An Excerpt from the link given above:
They don't actually create a response. They are preprocessors of the request before it reaches a servlet, and/or postprocessors of the response leaving a servlet.
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 231
thanks
Remko Strating and Adeel Ansari for your response

i didnt found answere to my question in your response
what iam asking is How the instances of the Filter are maintained
in the web server


in struts action-servlet instance is only once created

similar to action servlet filter objects are created once or created new for
every new request or created for every new session
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Adeel's answer covered it.
A Filter's life cycle is like a servlet's
For more information read section SRV.6.2.1 in the servlet specification:


SRV.6.2.1 Filter Lifecycle
After deployment of the Web application, and before a request causes the container
to access a Web resource, the container must locate the list of filters that must be
applied to the Web resource as described below. The container must ensure that it
has instantiated a filter of the appropriate class for each filter in the list, and called its
init(FilterConfig config) method. The filter may throw an exception to indicate
that it cannot function properly. If the exception is of type UnavailableException,
the container may examine the isPermanent attribute of the exception and may
choose to retry the filter at some later time.
Only one instance per <filter> declaration in the deployment descriptor is
instantiated per Java Virtual Machine (JVMTM) of the container. The container

provides the filter config as declared in the filter´┐Żs deployment descriptor, the
reference to the ServletContext for the Web application, and the set of
initialization parameters.






Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 231
thanks for correcting me ben
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: filter objects
 
Similar Threads
request Attribute vs session attribute
New instance or mutithreading
Slap me silly, but...
hibernate session
Back button