In this tutorial you will introduce to a web technology servlet and also know how it works

Introduction to Servlet

A Servlet is a server side program written in java which
handles client request coming from web browser through a network. It is basically java classes
which implements javax.servlet.Servlet*; interface. It is the convenient
means of generating dynamic web page. The execution of servlet
is started by the servlet container, the servlet container is responsible of
initializing, executing, and destroying the servlet. A servlet class doesn't
have a main method, therefore it can not execute itself directly. Servlets are protocol specific, for example for handling HTTP request you
need to extend HTTPServlet class of javax.servlet.http*; package.

request/response between client and servlet

When the container started it initializes the servlet, and
keep into the memory, when request comes, the container forwarded it to the
servlet object. The servlet can only once initialized and destroyed within
its life cycle but it can handle many requests. The response generated by
the servlet is commonly in the form of HTML which run on the browser. The
servlet basically contains two methods service(). This method takes
reference of two interfaces ServletRequest and ServletResponse.
Servletrequest for getting request from the client and ServletResponse for
generating appropriate response to the client. The servlet contains the HTML
code inside it println("<HTML>") tag. On running the servlet this HTML
appears on the web browser.

You need to set the content type of the response or MIME
type, so that
the servlet can response in that type. HTML/Text is the common response type
widely used. You can set it as