Introduction of JSP in Java

Java Server Pages(JSP) is a server-side technology that is used to create web applications just like Servlet technology. It is generally used for implementing the GUI of the application.

In this JSP tutorial, I am going to cover the Introduction of JSP and some important information about the JSP that you should know before writing the JSP code.

What is JSP?

JSP stands for Java Server Pages.JSP is a server-side programming technology that is used to create a dynamic Web application by inserting Java Code into the HTML page by making use of Special JSP tags.

  • It is an extension to servlet technology because it has more functions than Servlet.
  • JSP has access to Java APIs, including JDBC API.
  • JSP consists of either HTML or XML  and sometimes both and with JSP actions and commands.
  • A complete JSP code is like an HTML code along with some embedded Java Code.
  • JSP helps you to collect input from users through Webpages forms, insert records, and create a web page.
  • JSP is used for the separation of the View layer and the business logic layer in any web application.

Why Learn JSP?

JSP is an extension to Servlet technology because it provides more features and functionality to easily create a view.

  • JSP page has HTML code and also provides the functionality to include Java Code.
  • Since Web application has lots of user screens, So JSP can help us into it.
  • JSP provides extra functionality such as JSP Tags, Expression Tags, Custom Tags(that we will see in the coming tutorial)
  • It can be used in combination with a servlet that handles business logic.

Thus JSP is an important part of JAVA EE and plays a vital role in creating web applications.

JSP Architecture

As Servlet needs a Servlet container to run Servlet Programs Just like that For JSP pages to run we need a JSP Engine i.e a Container to process JSP pages. JSP Engine i.e a container works in combination with WEB Server to provide an Environment for the JSP page.

  • First, the Client sends an HTTP Request to the Web Server.
  • The WEB server recognizes the request. If the request is for the JSP page it will forward it to JSP Engine.
  • The JSP Engine now loads the page and convert it into servlet content.
  • Then the JSP Engine compiles the servlet into executable code and forwards the request to Servlet Container.
  • Servlet Container now loads the Servlet class and processes it and executes it and then HTTP response is sent to the Web Server.
  • The Web Server forwards the HTTP response to your browser.
  • At last, the client(the web browser) will handle the dynamically generated HTML page inside the HTTP response.

History of JSP

JSP i.e Java Server Pages are built on Servlet technology and are much easier than it. When Servlet was required for developing a business logic layer then the look and feel were missing so Thanks to Sun Microsystems, they released JSP in 1998.

The official version of it was released in 1999 which was 1.0 and 1.1. The most popular version was 1.2. Each JSP page is internally converted into a servlet by the server. Sun made it easy to write a dynamic HTML page. Together Servlet and JSP enable us to develop a Modular, maintainable, scalable web application.

Advantages of JSP

JSP has lots of advantages over servlet technology

  • It is an extension of servlet technology. In addition to the servlet feature, we can use JSP features also.
  • JSP is easily maintainable because we can separate the business logic and presentation layer.
  • If the JSP page is modified we don’t need to recompile and redeploy the application.
  • In JSP, we can use tags which reduces coding.

In the next section of the tutorial, we will discuss How to set up an Environment for the JSP page to run and we will also see a simple example using JSP.