A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Why do we use jsp in place of Servlet ? Can you explain life-cycle of JSP Page ? What are the API's being used in JSP ? Does All the Generated Servlet implements JspPage interface ?

Jsp is a technology in Java Programming Language. It provides a lots of additional features like
jstl, expression languages, jsp tags, directives, action element etc.


Why do we use jsp in place of Servlet ?

This is the favorite question of almost interviewer. But, If I have to explain it in single
sentence, then I can say that "JSP is easy to maintain at server side, Developer doesn't need
to compile if he modifies something in JSP. He just refresh the page and content will be
loaded in single moment. There is another major advantage is that Less code than Servlet.
So that Faster development".


Can you explain life-cycle of JSP Page ?


There are some of the following steps below:
1. JSP Page Translation
2. JSP Page Compilation
3. Classloading process in which classes are loaded by classloader.
4. Instantiation means Object will be created by respective Generated Servlet.
5. Initialization Occurs due to invoke of jspinit() method by Servlet Container.
6. Service Stage in which Request Processing Occurs by JspService method due to Servlet Container.
7. Destroy Stage :Finally, jspDestroy() method completed, which is invoked by Servlet Container. 

What are the API's being used in JSP ?


Generally, JSP API is known as javax API which consists of two parent packages as below:
1. java.servlet.jsp
2. javax.servlet.jsp.tagext


java.servlet.jsp is a package, that contains two interfaces and some classes as below:
Interfaces are JspPage and HttpJspPage. However, classes are as below:
1. JspWriter
2. PageContext
3. JspFactory
4. JspEngineInfo
5. JspException
6. JspError


Does All the Generated Servlet implements JspPage interface ?


Yes, according to the JSP specification.  It is possible because JspPage interface
extends Servlet interface and So that HttpJspPage extends JspPage and JspPage extends Servlet.

There are two method of JspPage Interface:
1. jspInit() method.
2. jspDestroy() method.


jspInit() method is initialized only once and till service completion. This page works well
as requested multiple time no need to initialized again and again.

jspDestroy() method is used to destroy the life cycle of servlet who has completed services
and container has no work till time.

LEARN TUTORIALS

.

.