1

According to the post how do servlets work instantiation servlets, listeners and filters are instantiated when the server parses the web.xml file. But listeners and filters are only getting instantiated. Servlets are not getting instantiated.

So are servlets instantiated at parsing web.xml or when requests come?

Community
  • 1
  • 1

1 Answers1

1

It depends on how you configured.

If you want to instantiate during startup, you should give <load-on-startup> in web.xml

else Servlet is instantiated when the container receives the first request.

In either case the same instance is used to serve subsequent requests.

Bhargav Kumar R
  • 2,190
  • 3
  • 22
  • 38