JSP Tutorial

This section will help you in to understand What is JSP ?, What are the features of JSP ?, What is a JSP page ?, Why use JSP?, Life cycle of JSP, Versions of JSP, Implicit objects in JSP, JSP scriptlets, JSP directives, Actions in JSP.

JSP Tutorial

JSP Tutorial


In this section you will learn about the JSP.

This section will help you in to understand What is JSP , What are the features of JSP ?, What is a JSP page ?, Why use JSP?, Life cycle of JSP, Versions of JSP, Implicit objects in JSP, JSP Scriptlets, JSP directives, Actions in JSP.

What is JSP ?

JSP is an acronym for JavaServer Pages. JSP is a technology that facilitate web developer to build web applications using both static and dynamic content. In a JSP page a web developer can write HTML code along with the Java Code. Java codes are written on the JSP page within JSP tag <% %>, codes written inside these tags are executed inside the Java Servlet technology.

What are the features of JSP ?

Features of JSP technology are as follows :

  • In JSP developers can insert java code directly into jsp file, due to which the web application's development as well as its maintenance becomes very simple and easy.
  • JSP pages are a text based documents where processing of a request and constructing of its response is described.
  • JSP supports the expression language using which server-side objects can be accessed.

What is a JSP Page ?

A JSP page is a text document which may contain the static data and dynamic contents. Static data can be in any text based format for example HTML, XML, SVG, WML whereas, dynamic contents can be constructed using JSP elements. File extension of a source file of JSP page is .jsp and the file extension of source file of fragment JSP page is .jspf. In a JSP page JSP elements can be used in either of the following two ways first way is using the Standard syntax and the second is using XML syntax.

Why use JSP?

In comparison to Servlet there are various advantages of using JSP.

  • JSP allows to use all the dynamic capabilities of Java Servlet technology as well as it provides the implicit objects, predefined JSP tags, the support of expression language.
  • In a JSP page business and presentation logic can be separated.
  • Re-deploy of project is not required if a JSP page is modified.
  • In JSP pages build process is performed automatically.

Life cycle of JSP

There is a Life cycle of JSP page which follows the following phases :

  • Translation & Compilation
  • Class loading (JSP page's Servlet class loading)
  • Instantiation (Instance of the Servlet class is instantiated)
  • Initialization (Instance of the Servlet is initializes by invoking jspInit method)
  • _jspService method is invoked by the container to pass request and response objects.
  • jspDestroy method is called by the container to destroy the JSP page's Servlet.

Implicit objects in JSP

There are nine(9) Implicit objects in JSP these are as follows :

  • request
  • response
  • out
  • session
  • application
  • config
  • pageContext
  • page
  • exception

JSP Scriptlets

JSP supports three types of scriptlet elements these are as follows :

  • scriptlet tag : <% %> called scriptlet tag. Java code is written within the scriptlet in JSP page.
  • expression tag : <%=  %> called expression tag. Code written within the expression tag is written to the output stream.
  • declaration tag : <%!  %> called declaration tag. Within declaration tag fields and methods is to be declared.

JSP directives

JSP supports three types of directive elements these are as follows :

  • page directive : page directive is used to provide the information to JSP page
  • include directive : include directive is used to include a file in the JSP page.
  • taglib directive : taglib directive is used to use the custom tags in the JSP pages.

Actions in JSP

Action tags or elements in JSP are defined for performing a specific tasks. There are various of actions tags are defined in JSP these are as follows:

  • jsp:include
  • jsp:param
  • jsp:forward
  • jsp:plugin
  • jsp:fallback
  • jsp:setProperty
  • jsp:getProperty
  • jsp:useBean