Servlets Tutorial Step 1

What is a Servlet?
Servlet is server side component, a servlet is pluggable extension to the server and servlets are used to extend the functionality of the java-enabled server.
Servlets are durable objects means that they remain in memory untill specially instructed to be destroyed.
Servlets will be loaded in the Address space of web server.

What is a Servlet Container?
Is a separate module to load and run servlets. Web server uses this module called Servlet Container or Servlet engine, for managing the servlets.

Normally Servlet container is a part of the web server. It can also exist as a separate process.
The servlet container are the following 3 types:
Standalone - Servlet containers of this type are typically web servers having the main web server and the servlet container as a single program.
In-process - Servlet containers of this type are typically having the main web server and the servlet container as different programs, but the container runs within the address space of the main server.
Out-of-process - Like in-process servers, the main web server and the servlet container
are different programs. But in different address spaces. Here they use a plug-in to communicate each other.

What is the difference between Server and Container?
A server provides many services to the clients. A server may contain one or more containers such as ejb containers, servlet/jsp container. A container holds a set of objects.
A servlet container can be built in component of Web server, or installed as an add-on component to a Web Server via that server’s native extension API. All servlet containers must support HTTP as a protocol for requests and responses, but additional request/response-based protocols such as HTTPS (HTTP over SSL) may be supported.

What is servlet API?
Servlet Application Programming Interfaces: The framework which is made up of a set of Java interfaces and classes collectively implementing the Sun’s Servlet specification, which is a standard and a platform-independent framework for communication between servlets and their containers.
The Servlet API is divided into two packages: javax.servlet and javax.servlet.http

javax.servlet package
The javax.servlet package contains a number of generic classes and interfaces that describe and define the contracts between a servlet and the container indepedent of protocol.
Some basic interfaces:

  • Servlet : Defines methods that all servlets must implement direcly or indirecly.
  • ServletConfig : A servlet configuration object used by a servlet container to pass information to a servlet during initialization.
  • ServletContext : Defines a set of methods used by servlet to communicate with its servlet container, for example, dispatch requests, or write to a log file.
  • ServletRequest : Defines an object to provide client request information to a servlet.
  • ServletResponse : Defines an object to provides methods for a servlet in sending a response to the client.
Some basic classes:
  • GenericServlet : Defines a generic, protocol-independent servlet. Implements Servlet, ServletConfig

javax.servlet.http package
This package provides the basic functionality required for HTTP servlets.
Interfaces and classes in this package extend the corresponding interfaces and classes of the javax.servlet package to provide support for the HTTP protocol.
Some basic interfaces:
  • HttpServletRequest : Extends the ServletRequest interface to provide request information for HTTP servlets.
  • HttpServletResponse : Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.
  • HttpSession : Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user.
Some basic classes :
  • Cookie :A cookie is a small amount of information sent by a servlet to a Web browser. the browser saves this information. Later browser sends the same information back to the server.
  • HttpServlet :Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site.
  • HttpUtils : Provides a collection of methods that are useful in writing HTTP servlets.

AddThis Feed Button
Please provide your feedback by sending an email to 1234java.blogspot@gmail.com. This would help me making the site more helpful. Thanks in advance.

DISCLAIMER:

The content provided in this article/site is not warranted or guaranteed by 1234java.blogspot.com. The content provided is intended for educational purposes in order to introduce to the reader key ideas, concepts. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials.