Professional Documents
Culture Documents
Servlet is basically a JAVA program that runs particularly inside JVM or {JAVA Virtual
Machine} on the Web server. It is generally used to make/create Dynamic web applications
and web pages.
It is a technology that is used to develop the Dynamic web applications. It uses the JAVA
language for its work of developing web pages. This technology is secured, scalable, and
robust because it uses JAVA technology which provides the same features.
This technology is very similar to CGI {Common Gateway Interface} but due to the
drawbacks of CGI Servlet overcame it. If we talk about the difference the main difference
between them is efficient and portable and data sharing is possible where it can handle the
cookies but on the other hand, CGI is not portable and sharing data is impossible then
resultant it cannot handle the cookies also.
Servlets API’s builds from two packages:
Javax.servlet {basic}
Javax.servlet http{advance}
Servlets Components
Servlet, ServletRequest, Filter, ServletConfig, HttpServlet, ServletResponse, GenericServlet,
HttpServletRequest
Types of Servlets
There are two main types of Servlet. They are Generic and HTTP servlets. We can use the
constructor method to initialize the Servlets with the help of init() and the destructor method
to remove the servlet from the resources using destroy(). There is a separate method called
service() to handle the servlet requests but they are handled in a different manner in both the
servlets.
Generic servlets extend javax.servlet.GenericServlet –
It is protocol independent servlet. Generic Servlet is a base class servlet from which all other
Servlets are derived. Generic Servlet supports for HTTP, FTP and SMTP protocols. It
implements the Servlet and ServletConfig interface. It has only init() and destroy() method of
ServletConfig interface in its life cycle. It also implements the log method of ServletContext
interface.
Session in Servlet
Session Tracking is remembering and recording of client conversion in span of time. It is also
called as session management.
If web application is capable of remembering and recording of client conversion in span of
time then that web application is called as stateful web application.
We need session tracking because
Http protocol is stateless, to make stateful between client and server we need Session
Tracking.
Session Tracking is useful for online shopping, mailing application, E-Commerce
application to track the conversion.
Http protocol is stateless, that means each request is considered as the new request.
You can see in below image.
Servlet technology allows four technique to track conversion, they are;
Cookies (Partial Session Tracking)
URL Rewriting (Complete Session Tracking)
Hidden Form Field (Partial Session Tracking)
HttpSession (Complete Session Tracking)