There isn't really a fixed "number of types" — servlets are categorized a couple of different ways:
By implementation hierarchy (2 main types):
- Generic Servlet — protocol-independent, extends
GenericServlet, overrideservice() - HTTP Servlet — protocol-specific (what you actually use 99% of the time), extends
HttpServlet, overridedoGet(),doPost(),doPut(),doDelete(), etc.
By behavior/spec (a looser, more "textbook" classification):
- Single-threaded servlets (implementing
SingleThreadModel— deprecated, don't use) - Multi-threaded servlets (default behavior — one instance, multiple threads handle requests)
Real talk: in practice, you just extend HttpServlet and override the HTTP methods you need. GenericServlet is rarely used directly since almost everything is HTTP-based anyway. The "single-threaded vs multi-threaded" distinction is legacy trivia at this point — SingleThreadModel was deprecated since Servlet 2.4 and nobody uses it.
Identity