What's the difference between a servlet and a controller?

What’s the difference between a servlet and a controller? I haven’t been able to find a clear comprehensive answer to that anywhere on the internet. Is any controller a servlet? Do controllers use servlets? How do the terms relate to each other? I’m able to write a web project (using Spring MVC functionality), but I still don’t get what “servlets” have to do with it (and things like doGet(), doPost(), doFilter(), etc.)

controller is the “C” in MVC model, you should look it up.
servlet is a java file, it receives requests from clients, then connect with the “Model” in MVC, to retreive or manipulate the database, then return suitable response to that client.

Hello, this is Gulshan Negi.
Well, in web development, servlets, and controllers serve distinct purposes. Servlets are utilized for dealing with low-level subtleties of HTTP solicitations and reactions, while regulators are utilized for carrying out more significant level application rationale in the MVC design. Although controllers are implemented as servlets in Spring MVC, the framework provides an abstraction layer that makes working with controllers without interacting directly with servlet programming simpler.

1 Like