JSP Basics

December 30, 2014

Java Server Pages or JSPs are very similar to typical html pages except they are embedded with java code. This simplifies the development of dynamic web applications.

How JSPs are related to Servlets

JSPs are basically an abstraction to Servlets. Before compilation, JSPs are translated into Servlets and then compiled by the servlet container.

JSP Lifecycle

  1. JSP is translated into a Servlet (creating equivalent Java source code for a servlet) and Compiled by the servlet container.
  2. An instance of the corresponding Servlet class is created and initialized by the by calling jspInit() method.
  3. This servlet object stays in the memory and for each request _jspService() method is invoked, passing the request and response objects.
  4. When the container needs to remove the servlet instance from service jspDestroy() method is called.

JSP Syntax