servlet filter lifecycle, doFilter


I read as below about servlet filter

To prepare the filter for service server calls init(FilterConfig) once, then calls doFilter().
The FilterConfig interface has methods for retrieving the filte name,init parameters, active servlet context.
The server calls destroy() to indicate that the filter is no longer in service.

Then filter can calls chain.doFilter() to shift control to the next filter.

I wonder why init called once. And how init call prepares a filter. To me filter lifecycle looks similar to servlet. How they are different

i thought doFilter is to intercept request and response but i wonder how doFilter() shifts control to other filter.

  chain.doFilter(request, response);

I do not see the name of other filter name in above line. How it doescall other filter.

Please advise.

Any links resources ideas highly appreciated. Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The init method is used for initialisation of an object. It's called only once because each object needs to be initialised only one during its lifetime. If it was initialised multiple times then it would loose all the state.
gudii9Author Commented:
>> If it was initialised multiple times then it would loose all the state.

Even if we initialize with state information still it looses state information. Please advise
What do you mean by "state information"?
gudii9Author Commented:
I mean init method is used for initialisation of an object, does initialised multiple times initilizes object multiple times by resetting back to default everytime?
The init() is only called once, you cannot call it multiple times. If it's called again it means you have a different servlet instance.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.