JSP stands for Java Sever Page.
Java Server Page used to create pages which can be visible o the end user while using the web application. Example:
- Login.jsp
- Registration.jsp
Java Server Page is extension of servlet technology to help developer to create dynamic pages with HTML like syntax.
We can create user interface/view in servlet also but the code will become very ugly and error-prone.
JSP life cycle :-
Translation:
JSP container checks the JSP code and parse it to servlet source code (JAVA Code).
If JSP name is login.jsp then its translated source file name will be login_jsp.java and class name will be Login_jsp.


Compilation:
Java Server Page container compiles the source code and produces the class file and loads the class into memory (Class loading).
Initialization [ init() ] :
Typically initialization is performed only once.
In init() method we generally initialize data member, open database connection, open files, etc.
Public void Init() {
// Initialization code
}
Request Processing [ Service() ] :
To process the client request service() method gets invoked.
Service() method will get called for every new request.
For every request new thred will get spawn.
Public void Service(HttpServletRequest req, HttpServletResponse res)
{
// Service handling code
}
JSP Cleanup [ Destroy() ] :
This is the last phase of JSP life cycle where JSP class is unloaded from the memory.
Usually we perform the cleanup action in destroy() method like closing database connection, closing open files, etc.
Public void Destroy() {
// Cleanup code
}

Different tags in JSP :-
Scriptlet tag :-
<% %>
Used to write java code in jsp (initialization).
Declaration tag :-
<%! %>
Used to declare data member.
Expression tag :-
<%= %>
Used to print the value.
What are the JSP directives :-
The JSP directives are used to provide an instruction to the JSP container during translation of JSP to Servlet code.
You can code page directives anywhere in your jsp page but by convention page directive coded at the top of the jsp page.
@page :
It provide an attribute to the JSp container that get applied to entire JSP page.
Attributes of @page directive :
language , isErrorpage , pageEncoding , session , etc.
Example:
<%@ page language= “java” pageEncoding= “ISO-8859-1” %>
@include :
It is used to include one file to the another file.
This included file can be HTMl, JSP, text file, etc.
Example: <%@ include file= “error.jsp” %>
@taglib :
It is used to define the tag library with “taglib” as prefix in JSP.
We can use tag library in JSP by using JSTL.
Example:
<%@ taglib uri=“http://www.ajit.com/tags” prefix=“t” %>
In the above example we are using our tag named “ t ”. To use this tag we must specify the taglib, so that the JSP container get an information about the tag.
What are the JSP implicit object :-
JSP implicit objects are nothing but the java object that the container makes available to the developers in each page and developers can call them directly without being explicitly declared.
It is also called as Pre-define variables.
request: This is HttpServletRequest object associated with the request.
response: This is HttpServletResponse object associated with the response.
session: This is HttpSession object associated with the request.
out: This is printWriter object used to send output to the client.
application: This is Servlet Context object associated with application. context.
config: This is Servlet Config object associated with page.
page
pageContext
exception