Java – Java Servlet


I read many articles to understand Java servlet but I did not succeed.

Can you please give brief introduction of Java servlets (in easy language). What is a servlet? What are the advantages?

I can't understand the difference between server-side programming languages (PHP, ASP) and servlets.

Best Solution

A servlet is simply a class which responds to a particular type of network request - most commonly an HTTP request. Basically servlets are usually used to implement web applications - but there are also various frameworks which operate on top of servlets (e.g. Struts) to give a higher-level abstraction than the "here's an HTTP request, write to this HTTP response" level which servlets provide.

Servlets run in a servlet container which handles the networking side (e.g. parsing an HTTP request, connection handling etc). One of the best-known open source servlet containers is Tomcat.