How Jsp Work

JSP API

The JSP API consists of two packages:

  1. javax.servlet.jsp
  2. javax.servlet.jsp.tagext

javax.servlet.jsp package

The javax.servlet.jsp package has two interfaces

  1. JspPage
  2. HttpJspPage

The classes are as follows:

  • JspWriter
  • JspFactory
  • JspEngineInfo
  • PageContext
  • JspError
  • JspException

 

Note:– Acconding to jsp specification the servlet class which is generated from jsp page must be implements JspPage interface and HttpJspPage interface.

Methods of JspPage interface(javax.servlet.JspPage)

The JspPage interface provides the two life cycle method of JSP.

  1. public void jspInit(): It is invoked only once in life cycle of the JSP when client firstly request of any  JSP page . It is used to perform initialization. This method is call from servlet Init() method.
  2. public void jspDestroy(): It is invoked only once in the life cycle of the JSP .This method is call from servlet Destroy() method .It is used to perform  clean up operation.

The HttpJspPage interface(javax.servlet.HttpJspPage)

The HttpJspPage interface provides the one life cycle method of JSP. It extends the JspPage interface.

Method of HttpJspPage interface:

  1. public void _jspService(): It is invoked each time when request for the JSP page comes to the container. It is used to process the request. This method is call from servlet Service()method.

How jsp work

Step 1 :- Web Container translates JSP code into a servlet class source(.java) file.

Step 2:- Compiler  compile .java file and generate .class file.

Step 3:– The classloader load .class file and Web Container  creates an instance of that servlet class.

Step 4:- Web Container call the jspInit()method to initialized servlet.

Step 5:- Web Container creates thread and  call the _jspService()method For each request.

Step 6:- When the Web Container removes the servlet instance from service, it calls the jspDestroy() method to perform any required clean up process.

 

jsp

2 thoughts on “How Jsp Work

Leave a comment