0% found this document useful (0 votes)
4 views

JSP Notes

Uploaded by

Sambit Swain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

JSP Notes

Uploaded by

Sambit Swain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

JSP (Java Server Page)

➔ It is improved version of servlet


➔ It is a combination of java and html

Java Java
HTML code Java code

Java code HTML code

Servlet JSP

JSP Life Cycle:


→Translation: -
This translation phase deals with the syntactic correctness of
JSP. Here JSP file is translated to java file
→compilation: -
Here the generated java file is compiled to a class file. Then
class loader loads class file into memory . The loaded class can then be
used to serve incoming requests for the JSP page.
→Instantiation
Here the container creates an instance for the class. The
container manages one or more instances by providing responses to
requests.
→initialization
JspInit() method is called only once during the life cycle
immediately after the generation of Servlet instance from JSP.
→service
_JspService() method is used to serve the raised requests by
JSP. It takes request and response objects as parameters. This method
can not be over ridden.
→destroy
Here JspDestroy() method is called only once during the life
cycle. If you need to perform any cleanup task like closing open files, or
releasing database connections jspDestroy() can be overridden.

In jsp we mainly make use of two packages:


Javax.servlet.jsp
Javax.servlet.jsp.tagext
These two packages are present in the servlet API
Here we write java codes in html page by using Tags
→scriptlet tag
→expression tag
→declaration tag
Scriptlet tag: -
It is written as <% %>
Scriptlet tag content are written into service method
Expression tag: -
It is indicated as <%= %>
It is used to print the java content to the html page.
Declaration tag: -
It is used for declaring any method and static and non-static
variable
Content of declaration tag is written outside the method.
Directive tags: -
Directives are written as <%@ %>
It is used for giving or adding more information to the JSP
There are 3 directives:
→page
→include
→taglib

1. Page directive: -
It is written as <%@page %>
→It is used for giving information to current JSP page.
Attributes of current JSP page: -
a. language: -
→This attribute tells about the language which is used and which
is translated late.
→value of this attribute is always java.
language=”java”
b. contentType: -
→this attribute decide what type of response need to be given.
contentType =”text/html”
c. pageEncoding: -
→this is about the character set included in the current page.
d. Import: -
→it is used to import library file.

e. errorPage: -
→This defines the destination page to which we need to redirect if
any error occurs in the current page.
f. isErrorPage: -
→This is used to indicate the current page is handling the error.
isErrorPage =”true”
g. extend: -
→by this attribute we can extend any class.
extends = ”com.example.xyz”
2.Include: -
It is used to include any jsp or html page to the current page
<%@ include=””%>
3.taglib: -
It is used for including 3rd party jsp tags (spring)
<%@taglib
prefix=”form” url=”http://www.springframework.org/tags/form”
%>

Implicit Objects: -
In JSP there are predefined words which represent the objects.
request → HttpServletRequest
response → HttpServletResponse
session → HttpSession
exception → Throwable
out → PrintWriter (JspWriter)
config → ServletConfig
application → ServletContext
page → Object
pageContext → PageContext

You might also like