• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Servlet

What is Servlet?

By Dinesh Thakur

Java servlets provide web developers with a simple consistent mechanism for extending the functionality of a web server and provide dynamic behaviour for web applications. Servlets are Java classes that function like CGI programs. They accept a request from a client (usually a web browser), process that request and return a response to the client. All servlets are loaded and executed by a servlet container that can run by itself or as a component of a web server. The servlet container is also referred to as a servlet engine in the early days of servlet technology.

Java applications are WORA (Write Once Run Any where). Java web applications are WODA application (Write Once Deploye Any where). Servlets is a Single Instance and Multiple threads principle base server side technology to develop server side components (A reusable java object is called as java “component”) as web resource programs of web applications.

Servlet is an API specification. That will be used by vendor (creators of s/w’s) companies as rules and guidelines to develop servlet container softwares and same thing will be used by programmers as base to develop java based web resource programs. Servlet API latest version is 3.0 but the running version is 2.5

When your web server (like Apache) gets a request for a servlet from the client, the server hands over the request not to the servlet itself, but to the servlet container in which servlet is deployed. The servlet container then directs the request to the appropriate servlet. The servlet does its processing which may include interacting with the database or other server side components such as servlets or JSPs (Java Server Pages). After the request is processed by servlet, the response (generally in the form of HTML Document) is returned back to the servlet container which in turn sends the response back to the client via the web server. It should be noted that a servlet is loaded by the servlet container, first time the servlet is requested. Afterwards, the servlet stays in memory waiting for other requests. Each request dispatched by the clients may be served simultaneously inside the same process and typically the servlet is unloaded only when the servlet container is shut down.

Servlet request response cycle

Servlets are generally used for

 

• Processing and / or storing data submitted using HTML form by the user such as purchase order or a credit card data.

• Providing dynamic contents (e.g. returning the results of a database query to the client).

• Allowing collaboration between people. A servlet can handle multiple requests concurrently i.e. they can synchronize requests to support systems such as online conferencing.

• Forwarding requests to other servers and servlets. This allows them to be used to balance load among several servers that mirror the same contents.

• Managing state information on the top of the stateless HTTP e.g. for an online shopping cart system which manages shopping carts from many concurrent customers and maps every request to the right customer.

Introduction To Web Resource

By Dinesh Thakur

• The logic and data of stand alone, desktop applications are specific to that computer where these applications are running.

• The logics and data of client-server applications, two-tier applications like JDBC applications are specific to one network where they are running. In the above said two-tier, client-server applications the server allows only known clients (recognized clients).

• To provide global visibility and accessibility to the logics and data of the applications. These applications allow both known and unknown clients having 24×7 accesses to the resources and logic data.

• When website is under development/testing in a software company then it is called as web application. Once web application is hosted on to the internet network by purchasing domain name (http://ecomputernotes.com) and space in the internet network is called as website.

• A web application is a collection of web resource programs which can generate web pages. There are two types of web resource programs based on the web page they generate.

1. Static web resource programs: generates static web pages.

        Example HTML.

2. Dynamic web resource programs: generates dynamic web pages.

 Example Servlet Program, JSP Program, ASP.net program and etc…..

 

 A web application is a collection of web resource programs.

        web application architecture                                                                    

• Static web page contains fixed content forever. The content of dynamic web page change based on the input values of the request or time of the request generation.

• Image file, Java Script file can’t generate web pages directly but they act as helper programs to another web resource programs. Web application is a collection of static, dynamic and helper (like image files) web resource programs.

• Stand alone applications, desktop applications and client-server applications will be executed by programmer manually. But the web resource programs of web application must be executed dynamically when they are requested by clients (Browser windows) so we can’t think about manual execution for web resource programs. we can use a special software called web server software to execute the web resource programs dynamically when they are requested by the clients.

• A web server software can also manage, execute multiple web applications simultaneously or parallely.

Example of web server / Http server Software’s

Tomcat

Resin

JWS (Java web server)

PWS (personal web server)

IIS (internet Information Server)

and etc.

• To develop and execute JDBC application we need the following setup.

   JDK Software, JDBC Driver, DB Software.

• Similarly to develop and execute web application we need the following setup.

   Browser Software, web server software, Db software

• Web server software used to manage and execute web application.

• Browser software used to request to web application.

• Java based web server internally use JDK Software.

Web server software (like Tomcat) supplies this servlet, JSP containers.

The development and execution step of web application.

development and execution step of web application 

 

• Each browser window acts as one client to web application.

 

• A web application can be developed as two tier application without database software or three tier applications with database software.

 

Diagram Explanation:

  1. Browser window generates request to web application.
  2. Web server takes the request and passes the request to appropriate web resource program of web application.

 3.   This web resource program will process the request and generates the results.

4. In this process the web resource program talks with DB s/w if necessary.

5. Web resource program sends the result to web server.

6. Web server sends the result to browser window as http response in the form of web page.

 

• Based on the place where web resource programs execute there are two types of web resource programs.

1. Server side web resource programs (they execute in the web server).

    Ex: Servlet Program, JSP Program, ASP.net program and etc…..

2. Client side web resource program, they come to browser window from web application placed in web server for execution.

• Decide whether web resource program is client side or server side based on the place where it executes not based on the place where it resides.

• A web application looks like thin client-fat server application.

• The process of keeping web application in web server is technically called as deployment and reverse process is called as under development.

 

« Previous Page

Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW