SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Java Server Pages
(JSP)
PRESENTED BY:
Manisha Keim
Introduction
 JSP (Java Server Pages) is server side technology to create
dynamic java web application.
 Allows Java programming code to be embedded in the HTML
pages.
 JSP contains an extension of .jsp
 After execution of a JSP page a plain HTML is produced and
displayed in the client's Web browser.
 JSP can be thought as an extension to servlet technology
because it provides features to easily create user views.
HTTP request
HTTP response
WEB
SERVER
JSP page
JSP container
compiles to
a servlet
URL
request
JavaBean
Library
DB
properties,
call methods
HTTP page
response
BROWSE
R
DATABASE
SERVER
JSP Architecture
Java Server Pages are part of a 3-tier architecture. A server will act as a mediator between
client browser and database.
JSP Architecture
 The following steps explain how the web server creates the web page using JSP:
 As with a normal page, your browser sends an HTTP request to the web server.
 The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This
is done by using the URL or JSP page which ends with .jsp instead of .html.
 The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very
simple in which all template text is converted to println( ) statements and all JSP elements are converted to
Java code that implements the corresponding dynamic behavior of the page.
 The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet
engine.
 A part of the web server called the servlet engine loads the Servlet class and executes it. During execution,
the servlet produces an output in HTML format, which the servlet engine passes to the web server inside
an HTTP response.
 The web server forwards the HTTP response to your browser in terms of static HTML content.
 Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if
it were a static page.
Loading
Instantiation
Initialization
RequestDestroy
Translation
Compilation
JSP
LIFECYCLE
Web Server
hello.jsp hello_jsp.java
Step: 1
Step: 2
hello_jsp.class
Step: 3Step: 4Step: 5
jspInit() Create
Step: 6
jspService()
Step: 7
jspDestroy()
Web Container
JSP Life Cycle
 Web Container translates JSP code into a servlet class
source(.java) file, then compiles that into a java servlet class.
In the third step, the servlet class bytecode is loaded using
classloader. The Container then creates an instance of that
servlet class.
 The initialized servlet can now service request. For each
request the Web Container call the jspService() method.
 When the Container removes the servlet instance from
service, it calls the jspDestroy() method to perform any
required clean up.
Web Container
 Translation – JSP pages doesn’t look like normal java classes, actually JSP container parse the
JSP pages and translate them to generate corresponding servlet source code. If JSP file name is
hello.jsp, usually its named as hello_jsp.java.
 Compilation – If the translation is successful, then container compiles the generated servlet
source file to generate class file.
 Class Loading – Once JSP is compiled as servlet class, its lifecycle is similar to servlet and it
gets loaded into memory.
 Instance Creation – After JSP class is loaded into memory, its object is instantiated by the
container.
 Initialization – The JSP class is then initialized and it transforms from a normal class to servlet.
 Request Processing – For every client request, a new thread is spawned with ServletRequest
and ServletResponse to process and generate the HTML response.
 Destroy – Last phase of JSP life cycle where it’s unloaded into memory.
JSP Life Cycle Phases
JSP Lifecycle Methods
Once a JSP page is translated to a servlet, the container invokes the following life
cycle methods on the servlet :
• jspInit() : This method is invoked at the time when the servlet is initialized.
• jspService() : This method is invoked when request for the JSP page is received.
• jspDestroy() : This method is invoked before the servlet is removes from the
service.
What happens to a JSP page when it is
translated into Servlet
• EXPRESSION enclosed in <%= and %> markers
A expression is used to insert the result of a Java expression directly into the
output.
• SCRIPTLET enclosed in <% and %> markers:
A scriptlet can contain any number of JAVA language statements, variable or
method declarations, or expressions that are valid in the page scripting language.
<%
String message = “Hello World”;
out.println (message);
%>
The time is : <%= new java.util.Date() %>
JSP Elements
• DIRECTIVES syntax - <%@ directive attribute = "value" %>
A JSP directive gives special information about the JSP page to the JSP Engine.
• There are three main types of directive :-
 page : processing information for this page
 include : files to be included
 taglib : tag library to be used in the page
<%@page import="java.util.Date" %>
<%
Date x = new java.util.Date();
out.println (x);
%>
Page is used in importing
external classes and providing
information about the page
<%@include file="externalContent.jsp" %>
include is used to
include the code
written in another file.
taglib is used to allow users use tags they
defined themselves using "custom tags"
• DECLARATION enclosed in <%! and %> markers
This tag allows the developer to declare variables or methods.
• Code placed in this must end in a semicolon(;).
• Declarations do not generate output, so are used with JSP expressions or
scriptlets.
<%! private int counter = 0 ;
private String getAccount (int accountNo); %>
HTML
JSP – ENVIRONMENT
SETUP
What is JDK? JRE?
 JRE: Java Runtime Environment. It is basically the Java Virtual
Machine where your Java programs run on.
 JDK: It's the full featured Software Development Kit for Java,
including JRE, and the compilers and tools to create and compile
programs.
 The JDK is a superset of the JRE, and contains everything that is in
the JRE.
 Sometimes, even though you are not planning to do any Java
Development on a computer, you still need the JDK installed.
Because application server will convert JSP into Servlets and
use JDK to compile the servlets.
Java – Environment Setup
QUESTIONS
A. Translate the JSP into a servlet.
B. Compile servlet source code.
C. Call _jspService()
D. Instantiate the servlet class.
E. Call jspInit()
F. Call jspDestroy()
Qus 1. Which JSP Lifecycle step is out of order?
A. <% page import=“java.util.Date” %>
B. <%@ page import=“java.util.Date” @%>
C. <%@ page import=“java.util.Date” %>
D. <% import java.util.Date %>
Qus 2. Which is an example of the syntax used to
import a class in a JSP?
To Display:
"Good Morning", if it is between 3:00am and 12:00pm
"Good Afternoon", if it is between 12:00pm and 6:00pm
"Good Evening", if it is after 6:00 pm
Qus 3.
References
 http://www.studytonight.com/jsp/lifecycle-of-jsp.php
 https://www.ntu.edu.sg/home/ehchua/programming/java/JSPB
yExample.html
 http://met.guc.edu.eg/OnlineTutorials/JSP%20-
%20Servlets/A%20simple%20JSP%20example.aspx
 Head First JavaScript Programming: A Brain-Friendly Guide
 https://www.tutorialspoint.com/java/java_environment_setup.h
tm
S
THANK YOU ☺

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlets
ServletsServlets
Servlets
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Features of java
Features of javaFeatures of java
Features of java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Java I/O
Java I/OJava I/O
Java I/O
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Ajax
AjaxAjax
Ajax
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Java web application development
Java web application developmentJava web application development
Java web application development
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java swing
Java swingJava swing
Java swing
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 

Ähnlich wie Java Server Pages(jsp)

Ähnlich wie Java Server Pages(jsp) (20)

Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
JSP overview
JSP overviewJSP overview
JSP overview
 
JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Arpita industrial trainingppt
Arpita industrial trainingpptArpita industrial trainingppt
Arpita industrial trainingppt
 
Jsp
JspJsp
Jsp
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
 
Java JSP.pptx
Java JSP.pptxJava JSP.pptx
Java JSP.pptx
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 

Mehr von Manisha Keim

Mehr von Manisha Keim (20)

National Rail Museum
National Rail MuseumNational Rail Museum
National Rail Museum
 
Electricity
ElectricityElectricity
Electricity
 
Health, Hygiene and Cleanliness
Health, Hygiene and CleanlinessHealth, Hygiene and Cleanliness
Health, Hygiene and Cleanliness
 
Transport Layer Numericals
Transport Layer NumericalsTransport Layer Numericals
Transport Layer Numericals
 
Physical Layer Questions
Physical Layer QuestionsPhysical Layer Questions
Physical Layer Questions
 
Network Layer Numericals
Network Layer NumericalsNetwork Layer Numericals
Network Layer Numericals
 
Data Link Layer Numericals
Data Link Layer NumericalsData Link Layer Numericals
Data Link Layer Numericals
 
Circle
CircleCircle
Circle
 
Rational Numbers
Rational NumbersRational Numbers
Rational Numbers
 
Data Handling
Data HandlingData Handling
Data Handling
 
Environment for Class IV
Environment for Class IVEnvironment for Class IV
Environment for Class IV
 
Tsunami
TsunamiTsunami
Tsunami
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Kabir
KabirKabir
Kabir
 
Abc Of Friendship
Abc Of FriendshipAbc Of Friendship
Abc Of Friendship
 
History of India
History of IndiaHistory of India
History of India
 
Moments
MomentsMoments
Moments
 
Coordinate Geometry
Coordinate GeometryCoordinate Geometry
Coordinate Geometry
 
Computers
ComputersComputers
Computers
 
Powepoint
PowepointPowepoint
Powepoint
 

Kürzlich hochgeladen

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Kürzlich hochgeladen (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

Java Server Pages(jsp)

  • 2. Introduction  JSP (Java Server Pages) is server side technology to create dynamic java web application.  Allows Java programming code to be embedded in the HTML pages.  JSP contains an extension of .jsp  After execution of a JSP page a plain HTML is produced and displayed in the client's Web browser.  JSP can be thought as an extension to servlet technology because it provides features to easily create user views.
  • 3. HTTP request HTTP response WEB SERVER JSP page JSP container compiles to a servlet URL request JavaBean Library DB properties, call methods HTTP page response BROWSE R DATABASE SERVER JSP Architecture Java Server Pages are part of a 3-tier architecture. A server will act as a mediator between client browser and database.
  • 4. JSP Architecture  The following steps explain how the web server creates the web page using JSP:  As with a normal page, your browser sends an HTTP request to the web server.  The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This is done by using the URL or JSP page which ends with .jsp instead of .html.  The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code that implements the corresponding dynamic behavior of the page.  The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine.  A part of the web server called the servlet engine loads the Servlet class and executes it. During execution, the servlet produces an output in HTML format, which the servlet engine passes to the web server inside an HTTP response.  The web server forwards the HTTP response to your browser in terms of static HTML content.  Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page.
  • 6. Web Server hello.jsp hello_jsp.java Step: 1 Step: 2 hello_jsp.class Step: 3Step: 4Step: 5 jspInit() Create Step: 6 jspService() Step: 7 jspDestroy() Web Container JSP Life Cycle
  • 7.  Web Container translates JSP code into a servlet class source(.java) file, then compiles that into a java servlet class. In the third step, the servlet class bytecode is loaded using classloader. The Container then creates an instance of that servlet class.  The initialized servlet can now service request. For each request the Web Container call the jspService() method.  When the Container removes the servlet instance from service, it calls the jspDestroy() method to perform any required clean up. Web Container
  • 8.  Translation – JSP pages doesn’t look like normal java classes, actually JSP container parse the JSP pages and translate them to generate corresponding servlet source code. If JSP file name is hello.jsp, usually its named as hello_jsp.java.  Compilation – If the translation is successful, then container compiles the generated servlet source file to generate class file.  Class Loading – Once JSP is compiled as servlet class, its lifecycle is similar to servlet and it gets loaded into memory.  Instance Creation – After JSP class is loaded into memory, its object is instantiated by the container.  Initialization – The JSP class is then initialized and it transforms from a normal class to servlet.  Request Processing – For every client request, a new thread is spawned with ServletRequest and ServletResponse to process and generate the HTML response.  Destroy – Last phase of JSP life cycle where it’s unloaded into memory. JSP Life Cycle Phases
  • 9. JSP Lifecycle Methods Once a JSP page is translated to a servlet, the container invokes the following life cycle methods on the servlet : • jspInit() : This method is invoked at the time when the servlet is initialized. • jspService() : This method is invoked when request for the JSP page is received. • jspDestroy() : This method is invoked before the servlet is removes from the service.
  • 10. What happens to a JSP page when it is translated into Servlet
  • 11. • EXPRESSION enclosed in <%= and %> markers A expression is used to insert the result of a Java expression directly into the output. • SCRIPTLET enclosed in <% and %> markers: A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language. <% String message = “Hello World”; out.println (message); %> The time is : <%= new java.util.Date() %> JSP Elements
  • 12. • DIRECTIVES syntax - <%@ directive attribute = "value" %> A JSP directive gives special information about the JSP page to the JSP Engine. • There are three main types of directive :-  page : processing information for this page  include : files to be included  taglib : tag library to be used in the page <%@page import="java.util.Date" %> <% Date x = new java.util.Date(); out.println (x); %> Page is used in importing external classes and providing information about the page <%@include file="externalContent.jsp" %> include is used to include the code written in another file. taglib is used to allow users use tags they defined themselves using "custom tags"
  • 13. • DECLARATION enclosed in <%! and %> markers This tag allows the developer to declare variables or methods. • Code placed in this must end in a semicolon(;). • Declarations do not generate output, so are used with JSP expressions or scriptlets. <%! private int counter = 0 ; private String getAccount (int accountNo); %>
  • 14. HTML
  • 16.
  • 17. What is JDK? JRE?  JRE: Java Runtime Environment. It is basically the Java Virtual Machine where your Java programs run on.  JDK: It's the full featured Software Development Kit for Java, including JRE, and the compilers and tools to create and compile programs.  The JDK is a superset of the JRE, and contains everything that is in the JRE.  Sometimes, even though you are not planning to do any Java Development on a computer, you still need the JDK installed. Because application server will convert JSP into Servlets and use JDK to compile the servlets.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 24.
  • 25.
  • 27. A. Translate the JSP into a servlet. B. Compile servlet source code. C. Call _jspService() D. Instantiate the servlet class. E. Call jspInit() F. Call jspDestroy() Qus 1. Which JSP Lifecycle step is out of order?
  • 28. A. <% page import=“java.util.Date” %> B. <%@ page import=“java.util.Date” @%> C. <%@ page import=“java.util.Date” %> D. <% import java.util.Date %> Qus 2. Which is an example of the syntax used to import a class in a JSP?
  • 29. To Display: "Good Morning", if it is between 3:00am and 12:00pm "Good Afternoon", if it is between 12:00pm and 6:00pm "Good Evening", if it is after 6:00 pm Qus 3.
  • 30. References  http://www.studytonight.com/jsp/lifecycle-of-jsp.php  https://www.ntu.edu.sg/home/ehchua/programming/java/JSPB yExample.html  http://met.guc.edu.eg/OnlineTutorials/JSP%20- %20Servlets/A%20simple%20JSP%20example.aspx  Head First JavaScript Programming: A Brain-Friendly Guide  https://www.tutorialspoint.com/java/java_environment_setup.h tm

Hinweis der Redaktion

  1. When you develop a webpage, you use HTML to describe what the page should look like and how it should behave.
  2. The _jspService() method can never be called before jspInit().