views:

61

answers:

2

is there any difference between servlet and filter lifecycle?.

+2  A: 

No, both a servlet and a filter:

  • are instantiated (once) when the context starts
  • the init(..) method is called
  • they handle each request - first it passes through all filters and then reaches the servlet
  • when the context is destroyed (i.e. when your container stops, or your application is undeployed from the manager console), the destroy(..) method is called
Bozho
A: 

I can add that in filters you should invoke next filter in the chain if needed.

Andriy Sholokh