SlideShare a Scribd company logo
Java Server Page

• Deisigned By:
• Shivendra Srivastwa
• Java and Android consultant
Java Server Page (JSP)
JSP technology is used to create web
application just like Servlet technology. It
can be thought of as an extension to the
servlet because it provides more
functionality than servlet.
 A JSP page contains HTML code and
JSP tags. The jsp pages are easier to
maintain than servlet because we can
separate designing and development. It
provides some additional features such
as Expression Language, Custom Tag
etc.

Advantage of JSP over
Servlet
JSP is the extension to the servlet
technology. We can use all the features of
Servlet in JSP.
 In addition to, we can use implicit
objects, predefined tags, expression
language and Custom tags in JSP, that
makes JSP development easy.
 JSP can be easily managed because we can
easily separate our business logic with
presentation logic. In servet, we mix our
business logic with the presentation logic.
 If JSP page is modified, we don't need to
redeploy the project. The servlet code needs
to be updated and recompiled if we have to
change the look and feel of the application.

Life cycle of a JSP Page







Compilation of JSP Page
Classloading (class file is loaded by the
classloader)
Instantiation (Object of the Generated
Servlet is created).
Initialization ( jspInit() method is invoked
by the container).
Reqeust processing ( _jspService()
method is invoked by the container).
Destroy ( jspDestroy() method is invoked
by the container)
JSP page is translated into servlet by the help of JSP
translator. The JSP translator is a part of webserver that is
responsible to translate the JSP page into servlet. Afterthat
Servlet page is compiled by the compiler and gets converted
into the class file. Moreover, all the processes that happens in
servlet is performed on JSP later like initialization, commiting
response to the browser and destroy.
Directory structure of JSP
The JSP API
The JSP API consists of two packages:
1. javax.servlet.jsp package
2. javax.servlet.jsp.tagext
javax.servlet.jsp package
The Interfaces are as follows:
1. JspPage
HttpJspPage
The classes are as follows:
1. JspWriter
2. PageContext
3. JspFactory
4.JspEngineInfo
5.JspExceptionJspError

2.
According to the JSP
specification, all the generated
servlet classes must
implement the JspPage
interface. It extends the Servlet
interface. It provides two life
cycle methods.

The JspPage interface
METHODS OF JSPPAGE
INTERFACE
public void jspInit()
It is invoked only
once during the life
cycle of the JSP
when JSP page is
requested firstly. It
is used to perform
initialization. It is
same as the init()
method of Servlet
interface.

public void
jspDestroy():
It is invoked only
once during the life
cycle of the JSP
before the JSP
page is destroyed.
It can be used to
perform some clean
up operation.
THE HTTPJSPPAGE
INTERFACE
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. The
underscore _ signifies that you cannot
override this method.
JSP scripting Element
The scripting elements provides the
ability to insert java code inside the
jsp. There are three types of scripting
elements:
 Scripting elements:


◦ 1. scriptlet tag
◦ 2. expression tag
◦ 3. declaration tag
Scriptlet tag
A scriptlet tag is used to execute java
source code in JSP. Syntax is as
follows:
 Syntax:
<% java source code %>

JSP expression tag
The code placed within expression tag
is written to the output stream of the
response.
 So you need not write out.print() to
write data. It is mainly used to print the
values of variable or method.
 Syntax: <%= statement %>

JSP declaration tag
The JSP declaration tag is used to
declare fields and methods. The code
written inside the jsp declaration tag is
placed outside the service() method of
auto generated servlet. So it doesn't
get memory at each request
 Syntax:
<%! statement %>

Difference between the jsp
scriptlet tag and jsp declaration
tag

The jsp scriptlet tag can only declare
variables not methods whereas jsp
declaration tag can declare variables
as well as methods.
 The declaration of scriptlet tag is
placed inside the _jspService()
method whereas the declaration of jsp
declaration tag is placed outside the
_jspService() method.

Implicit Object


There are 9 implicit objects available
for the JSP page. The Auto Generated
Servlet contains many objects like out,
request, config, session, application
etc.
out implicit object
For writing any data to the buffer, JSP
provides an implicit object named out.
 Syntax:


 out.print();
request implicit object
In JSP, request is an implicit object of
type HttpServletRequest. Let's see the
simple example of request implicit
object where we are printing the name
of the user with welcome message.
 eg: request.getParameter

response implicit object


In JSP, response is an implicit object
of type HttpServletResponse. Let's
see the example of response implicit
object where we are redirecting the
request to the Google.
config implicit object
In JSP, config is an implicit object of
type ServletConfig. This object can be
used to get configuration information
for a particular JSP page.
 This variable information can be used
for one jsp page only.

application implicit object


In JSP, application is an implicit object
of type ServletContext.This object can
be used to get configuration
information from configuaration
file(web.xml). This variable information
can be used for all jsp pages.
session implicit object


In JSP, session is an implicit object of
type HttpSession.The Java developer
can use this object to set,get or
remove attribute or to get session
information.
pageContext implicit object
In JSP, pageContext is an implicit
object of type PageContext class.The
pageContext object can be used to
set,get or remove attribute from one of
the following scopes:
 i. Page
ii. Request
 Iii. Session iv. Application
 Note: page scope is the default scope

exception implicit object


In JSP, exception is an implicit object
of type java.lang.Throwable class.
This object can be used to print the
exception. But it can only be used in
error pages.It is better to learn it after
page directive. Let's see a simple
example:
Happy Programming with JSP
Thanks…………

More Related Content

What's hot

Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginners
Singsys Pte Ltd
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Jennifer Estrada
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
ShahDhruv21
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
Rishi Kothari
 
Html frames
Html framesHtml frames
Html frames
eShikshak
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
Kang-min Liu
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
WordPress Memphis
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
BhagyashreeGajera1
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Angular data binding
Angular data binding Angular data binding
Angular data binding
Sultan Ahmed
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
akhilsreyas
 

What's hot (20)

Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginners
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Html frames
Html framesHtml frames
Html frames
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Java script
Java scriptJava script
Java script
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Servlets
ServletsServlets
Servlets
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
Angular data binding
Angular data binding Angular data binding
Angular data binding
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 

Similar to Jsp Introduction Tutorial

Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
ManishaPatil932723
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp
JspJsp
JSP overview
JSP overviewJSP overview
JSP overview
Amisha Narsingani
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
Anuj Singh Rajput
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
NishaRohit6
 
Jsp
JspJsp
Jsp interview questions by java training center
Jsp interview questions by java training centerJsp interview questions by java training center
Jsp interview questions by java training centerMaheshit Jtc
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Shah Nawaz Bhurt
 
Jsp
JspJsp
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Yoga Raja
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
Kalpana T
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
IMC Institute
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
Subhasis Nayak
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
WebStackAcademy
 
anatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptxanatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptx
Sameenafathima4
 

Similar to Jsp Introduction Tutorial (20)

Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Jsp
JspJsp
Jsp
 
JSP overview
JSP overviewJSP overview
JSP overview
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Jsp
JspJsp
Jsp
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Jsp interview questions by java training center
Jsp interview questions by java training centerJsp interview questions by java training center
Jsp interview questions by java training center
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
 
anatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptxanatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptx
 

Recently uploaded

Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 

Recently uploaded (20)

Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 

Jsp Introduction Tutorial

  • 1. Java Server Page • Deisigned By: • Shivendra Srivastwa • Java and Android consultant
  • 2. Java Server Page (JSP) JSP technology is used to create web application just like Servlet technology. It can be thought of as an extension to the servlet because it provides more functionality than servlet.  A JSP page contains HTML code and JSP tags. The jsp pages are easier to maintain than servlet because we can separate designing and development. It provides some additional features such as Expression Language, Custom Tag etc. 
  • 3. Advantage of JSP over Servlet JSP is the extension to the servlet technology. We can use all the features of Servlet in JSP.  In addition to, we can use implicit objects, predefined tags, expression language and Custom tags in JSP, that makes JSP development easy.  JSP can be easily managed because we can easily separate our business logic with presentation logic. In servet, we mix our business logic with the presentation logic.  If JSP page is modified, we don't need to redeploy the project. The servlet code needs to be updated and recompiled if we have to change the look and feel of the application. 
  • 4. Life cycle of a JSP Page       Compilation of JSP Page Classloading (class file is loaded by the classloader) Instantiation (Object of the Generated Servlet is created). Initialization ( jspInit() method is invoked by the container). Reqeust processing ( _jspService() method is invoked by the container). Destroy ( jspDestroy() method is invoked by the container)
  • 5. JSP page is translated into servlet by the help of JSP translator. The JSP translator is a part of webserver that is responsible to translate the JSP page into servlet. Afterthat Servlet page is compiled by the compiler and gets converted into the class file. Moreover, all the processes that happens in servlet is performed on JSP later like initialization, commiting response to the browser and destroy.
  • 7. The JSP API The JSP API consists of two packages: 1. javax.servlet.jsp package 2. javax.servlet.jsp.tagext
  • 8. javax.servlet.jsp package The Interfaces are as follows: 1. JspPage HttpJspPage The classes are as follows: 1. JspWriter 2. PageContext 3. JspFactory 4.JspEngineInfo 5.JspExceptionJspError 2.
  • 9. According to the JSP specification, all the generated servlet classes must implement the JspPage interface. It extends the Servlet interface. It provides two life cycle methods. The JspPage interface
  • 10. METHODS OF JSPPAGE INTERFACE public void jspInit() It is invoked only once during the life cycle of the JSP when JSP page is requested firstly. It is used to perform initialization. It is same as the init() method of Servlet interface. public void jspDestroy(): It is invoked only once during the life cycle of the JSP before the JSP page is destroyed. It can be used to perform some clean up operation.
  • 11. THE HTTPJSPPAGE INTERFACE 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. The underscore _ signifies that you cannot override this method.
  • 12. JSP scripting Element The scripting elements provides the ability to insert java code inside the jsp. There are three types of scripting elements:  Scripting elements:  ◦ 1. scriptlet tag ◦ 2. expression tag ◦ 3. declaration tag
  • 13. Scriptlet tag A scriptlet tag is used to execute java source code in JSP. Syntax is as follows:  Syntax: <% java source code %> 
  • 14. JSP expression tag The code placed within expression tag is written to the output stream of the response.  So you need not write out.print() to write data. It is mainly used to print the values of variable or method.  Syntax: <%= statement %> 
  • 15. JSP declaration tag The JSP declaration tag is used to declare fields and methods. The code written inside the jsp declaration tag is placed outside the service() method of auto generated servlet. So it doesn't get memory at each request  Syntax: <%! statement %> 
  • 16. Difference between the jsp scriptlet tag and jsp declaration tag The jsp scriptlet tag can only declare variables not methods whereas jsp declaration tag can declare variables as well as methods.  The declaration of scriptlet tag is placed inside the _jspService() method whereas the declaration of jsp declaration tag is placed outside the _jspService() method. 
  • 17. Implicit Object  There are 9 implicit objects available for the JSP page. The Auto Generated Servlet contains many objects like out, request, config, session, application etc.
  • 18.
  • 19. out implicit object For writing any data to the buffer, JSP provides an implicit object named out.  Syntax:   out.print();
  • 20. request implicit object In JSP, request is an implicit object of type HttpServletRequest. Let's see the simple example of request implicit object where we are printing the name of the user with welcome message.  eg: request.getParameter 
  • 21. response implicit object  In JSP, response is an implicit object of type HttpServletResponse. Let's see the example of response implicit object where we are redirecting the request to the Google.
  • 22. config implicit object In JSP, config is an implicit object of type ServletConfig. This object can be used to get configuration information for a particular JSP page.  This variable information can be used for one jsp page only. 
  • 23. application implicit object  In JSP, application is an implicit object of type ServletContext.This object can be used to get configuration information from configuaration file(web.xml). This variable information can be used for all jsp pages.
  • 24. session implicit object  In JSP, session is an implicit object of type HttpSession.The Java developer can use this object to set,get or remove attribute or to get session information.
  • 25. pageContext implicit object In JSP, pageContext is an implicit object of type PageContext class.The pageContext object can be used to set,get or remove attribute from one of the following scopes:  i. Page ii. Request  Iii. Session iv. Application  Note: page scope is the default scope 
  • 26. exception implicit object  In JSP, exception is an implicit object of type java.lang.Throwable class. This object can be used to print the exception. But it can only be used in error pages.It is better to learn it after page directive. Let's see a simple example:
  • 27. Happy Programming with JSP Thanks…………