Scroll to top

JSP Introduction

Hello everyone, in this tutorial series you are going to learn about JSP and Servlets from scratch. In order to gain an understanding of JSP, you must first know about Web Applications, what are they and how do they function? Let’s take a look.

Web Applications

To put it in simple terms, “A web application is such a website where the pages are generated dynamically, based on the user’s choices and actions”. Websites such as E-Commerce Stores and Travel Sites are web applications. There are 3 main components of any web application. There is:

  • The Web Browser
  • The Web Server
  • The Database

What happens is that when a user sends a request to the webserver, the server then submits a query to the database using structured query language (or SQL for short). The results of the SQL query will be collected by the web server and then combining them with HTML send the page back to the user at the browser.

This is the general idea of a web application. You can build web apps using any technology including .Net frameworks, JSP Servlets as well as many others. In these tutorials I’ll be focusing on JSP & Servlets. So now let’s take a look at what exactly are these?

JSP & Servlets

Both of them are Java Code which runs on the web server (but there is a small difference which shall be discussed later), acting as the middle man between the user requests coming from the browser and the webserver. So they can read what the user inputs through the HTML form and do the respective actions accordingly. Ultimately, returning a dynamically generated HTML page to the server.

JSP & Servlets commonly serve the same purpose as implementing the CGI (Common Gateway Interface). But Servlets usually offer various advantages when compared to the latter.

  • The response time of servlets is ominously better.
  • JSP Servlets are not dependent on any platform since they are written in Java.
  • JSP Servlets execute within the allocated space of a Web Server. It isn’t necessary to create separate processes to handle each of the request from a web browser.
  • The full functionality of Java libraries is available to the servlets, allowing them to communicate with databases, applets or any other software through RMI mechanisms and sockets.
  • Most importantly, the security manager enforces a set of limitations to safeguard the resources available on a server machine. This is why servlets are more trusted.

Tasks Handled by Jsp Servlets

Servlets can perform these tasks:

  • Read explicit data sent by the browsers, which usually includes and HTML form on a Web Page or some applet, maybe even a custom HTTP client.
  • Read implicit HTTP requests sent by the client browsers. Usually these requests are comprised of media types, cookies as well as compression schemes (understood by the browser) along with much more.
  • Process the requests and generate appropriate results. This process might involve communication with a database, maybe even executing a COBRA call or an RMI , invoking a service or figuring out the response to the request directly.
  • Send implicit HTTP response to the client browsers, which usually include telling the client or browser exactly what type of file is being returned. This allows the browsers to set caching parameters along with cookies and allows them to execute other similar tasks.
  • Send explicit data (which is the file being returned) to the client browser. This file can be in various formats such as HTML, XML or even GIF images, etc.

Using JSP and Servlets you can easily create any sort of web application, may it be a social network, hotel booking website, a student or employee tracking system or maybe even an E-commerce store. JSP and Servlets are the key components of the Java Empire and have many MVC frameworks based on them. In the next tutorial we are going to get down to work and learn how to set up the development environment for JSP and Servlet development.

Author avatar

Post a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.