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.
Jsp Introduction Tutorial
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…………
Ad

More Related Content

What's hot (20)

RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
trxcllnt
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
Angular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAngular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web Applications
Albiorix Technology
 
JavaFX Presentation
JavaFX PresentationJavaFX Presentation
JavaFX Presentation
Mochamad Taufik Mulyadi
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
MUHAMMAD FARHAN ASLAM
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
Nitin Pande
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
kamal kotecha
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
manojbkalla
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
Siva Priya
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
Aniruddh Bhilvare
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
Centre for Budget and Governance Accountability (CBGA)
 
LINQ
LINQLINQ
LINQ
Betclic Everest Group Tech Team
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
Bhargav Anadkat
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
Goa App
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 

Similar to Jsp Introduction Tutorial (20)

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 in Servlet by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Jsp
JspJsp
Jsp
Maheshit Jtc
 
Module 3.pptx.............................
Module 3.pptx.............................Module 3.pptx.............................
Module 3.pptx.............................
Betty333100
 
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
Pooja Verma
 
Java server pages
Java server pagesJava server pages
Java server pages
Abhishek Kesharwani
 
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
Maheshit Jtc
 
jsp elements java server tag with jsp elements .pptx
jsp elements java server tag with jsp elements .pptxjsp elements java server tag with jsp elements .pptx
jsp elements java server tag with jsp elements .pptx
yvtinsane
 
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 APP DEVLOPMENT.pptx Related to Android App Development
JSP  APP DEVLOPMENT.pptx Related to Android App DevelopmentJSP  APP DEVLOPMENT.pptx Related to Android App Development
JSP APP DEVLOPMENT.pptx Related to Android App Development
BhawnaSaini45
 
Jsp
JspJsp
Jsp
Rahul Goyal
 
Jsp
JspJsp
Jsp
Rahul Goyal
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
People Strategists
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
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
 
Module 3.pptx.............................
Module 3.pptx.............................Module 3.pptx.............................
Module 3.pptx.............................
Betty333100
 
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
Maheshit Jtc
 
jsp elements java server tag with jsp elements .pptx
jsp elements java server tag with jsp elements .pptxjsp elements java server tag with jsp elements .pptx
jsp elements java server tag with jsp elements .pptx
yvtinsane
 
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
 
JSP APP DEVLOPMENT.pptx Related to Android App Development
JSP  APP DEVLOPMENT.pptx Related to Android App DevelopmentJSP  APP DEVLOPMENT.pptx Related to Android App Development
JSP APP DEVLOPMENT.pptx Related to Android App Development
BhawnaSaini45
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
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
 
Ad

Recently uploaded (20)

U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
Ad

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.
  • 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…………
  翻译: