SlideShare a Scribd company logo
hSenid Lanka: Java Server Pages Presentation
 Introduction to JSP
 Introduction to Servlet
 JSP vs Servlet
 Architecture of JSP
 Life Cycle of a JSP Page
 JSP Scripting Elements
 JSP Directives
 JSP Implicit Objects
 Transferring Control of JSP
 MVC in JSP
2
hSenid Lanka: Java Server Pages Presentation
 Demo
o Create a JSP Page
o Create a Servlet
o Configure Servlet Using web.xml
o Parse Data Between JSP & Servlet
o Set Default Error Page
3
hSenid Lanka: Java Server Pages Presentation
• JSP is a server-side programming technology.
• Developed by Sun Microsystems in 1999.
• Fast way to create web pages to display dynamic
data.
• JSP page contains both static & dynamic data.
4
hSenid Lanka: Java Server Pages Presentation
• Helps to write web applications easily even with
a less knowledge in Java.
• Extension of a JSP page is .jsp or .jspx
• Initially JSP was developed to replace servlet
but now common practice is to use servlet and JSP
together using MVC (model-view-controller)
pattern.
5
hSenid Lanka: Java Server Pages Presentation
• Servlet is a server-side program.
• Executes in a web server (eg: Tomcat).
• Receives HTTP requests from users and returns
HTTP responses.
• Written in Java.
• Runs on every platform that supports Java.
• Supported my most popular web servers.
6
hSenid Lanka: Java Server Pages Presentation 7
Relationship between JSP & Servlet
• JSP is an interface on top of Servlets.
• A JSP program is compiled into a Java servlet before
execution.
• Why JSP?
 Easier to write than servlets
 Designers can write HTML, programmers can write
Java portions
• Servlets came first, followed by JSP.
hSenid Lanka: Java Server Pages Presentation 8
Advantages of Servlets
• Performance
 Get loaded upon first request
 Multithreading
 Each request runs in its own separate thread
• Simplicity
 Run inside controlled server environment
 No specific client software is needed: Web
browser is enough
hSenid Lanka: Java Server Pages Presentation 9
Fig: JSP Processing
hSenid Lanka: Java Server Pages Presentation 10
Client’s
Computer Server
1.Browser requests HTML
7. Server sends HTML
back to browser
servlet
servlet
class 5.The servlet
runs and
generates
HTML
Java Engine
6. Java Engine sends HTML to server
2. Server sends requests to Java Engine
3. If needed, the Java Engine
reads the .jsp file
4. The JSP is turned into a
servlet, compiled, and loaded
Bean JSP
hSenid Lanka: Java Server Pages Presentation 11
• A JSP life cycle can be defined as the entire
process from its creation till the destruction
• The following are the paths followed by a JSP
 Compilation has 3 steps
 Parsing JSP
 Turning the JSP into a servlet
 Compiling the servlet
 Initialization
 Execution
 Destroy
hSenid Lanka: Java Server Pages Presentation 12
[destroy]
jspDestroy()
[Execution ]
_jspService()
[Intialization]
jspInit()
Request
Response
hSenid Lanka: Java Server Pages Presentation 13
 There are three types of scripting
elements in JSP,
o Scriptlet tag
o Expression tag
o Declaration tag
hSenid Lanka: Java Server Pages Presentation 14
Scriptlet Tag
 In JSP, JAVA code can be written inside the JSP page
using Scriptlet tag.
Syntax:
<% java source code %>
Example:
<html>
<body>
<% out.print(“Hello world…”); %>
</body>
</html>
hSenid Lanka: Java Server Pages Presentation 15
Expression Tag
 Code placed within expression tag is written to the
output stream of the response. So, no need to write
out.print() to write data.
Syntax:
<%= Statement %>
Example:
<html>
<body>
<%= “Hello world!” %>
</body>
</html>
Note: Do not end statement with semicolon (;)
hSenid Lanka: Java Server Pages Presentation 16
Declaration Tag
 Used to declare fields and methods. The code written
inside this tag is placed outside the service() method
of auto generated servlet. So it doesn’t get memory at
each request.
Syntax:
<%! Statement %>
Example:
<html>
<body>
<%! int data=60; %>
<%= “Value is: “ + data %>
</body>
</html>
hSenid Lanka: Java Server Pages Presentation 17
 There are two types of JSP comment types that we are using.
 Hidden Comments (JSP comments)
o Visible only inside JSP page but not in the generated
HTML page
o Example:
<%-- This is a hidden JSP comment --%>
 Comments within HTML content
o Comments to be generated inside the output HTML page
o Example:
<!-- Comment inside the generated HTML -->
hSenid Lanka: Java Server Pages Presentation 18
• Directives are messages that tells the web container
how to translate a JSP page into corresponding
servlet.
• Three types:
 page directive
 include directive
 taglib directive
• Syntax of JSP directives
<%@ directive attribute=“value” %>
hSenid Lanka: Java Server Pages Presentation 19
page directive
• Defines attributes that apply to an entire JSP page.
• Syntax:
<%@ page attribute=“value” %>
• Attributes :
import, contentType, extends, info, buffer, language, autoFlush, session,
pageEncoding, errorPage, isErrorPage
hSenid Lanka: Java Server Pages Presentation 20
include directive
• Includes the contents of any resource(may be jsp file,
html file or text file.
• It includes the original content of the included
resources at page translation time.
• Reusability is the advantage.
• Syntax:
<%@include file=“resourcename” %>
hSenid Lanka: Java Server Pages Presentation 21
taglib directive
• Used to define a tag library that defines many tags.
• We use the TLD (Tag Library Descriptor) file to
define the tags.
• Syntax:
<%@ taglib uri=“uriofthetaglibrary”
prefix=“prefixoftaglibrary” %>
hSenid Lanka: Java Server Pages Presentation 22
 There are several objects that are automatically available in
JSP called implicit objects.
Variable Type
out JspWriter
request HTTPServletRequest
response HTTPServletResponse
config ServletConfig
application ServletContext
session HTTPSession
pageContext PageContext
page Object
exception Throwable
hSenid Lanka: Java Server Pages Presentation 23
out implicit object
• For writing any data to the buffer, JSP provides an
implicit object named out.
Syntax:
out.print();
request implicit object
• Access to information associated with a request. This
object is normally used in looking up parameter values
and cookies.
<% String str = request.getParameter(“uname”); %>
hSenid Lanka: Java Server Pages Presentation 24
config implicit object
• 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
• This object can be used to get configuration
information from configuration file(web.xml). This
variable information can be used for all JSP pages.
hSenid Lanka: Java Server Pages Presentation 25
session implicit object
• The Java developer can use this object to set, get or
remove attribute or to get session information.
pageContext implicit object
• 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
exception implicit object
• This object can be used to print the exception. But it
can only be used in error pages.
hSenid Lanka: Java Server Pages Presentation 26
• Transferring control explain how to redirect user to
another page from JSP. There are two methods.
 sendRedirect()
 forward()
hSenid Lanka: Java Server Pages Presentation 27
sendRedirect()
• Request is transfer to another resource to different
domain or different server for further processing.
• Container transfers the request to client or browser
so URL given inside the sendRedirect method is visible
as a new request to the client.
• When sendRedirect method calls, old request and
response objects are lost because it is treated as new
request by the browser.
hSenid Lanka: Java Server Pages Presentation 28
sendRedirect() Cont.
• We can notice the browser address bar URL will change.
• This method is slower because it involves two tasks
(requests).
 Create a new request
 Remove old request
• If we need to pass data using this method, we may need
to use session or pass data along with the URL.
hSenid Lanka: Java Server Pages Presentation 29
forward()
• Request is transfer to other resource within the same
server for further processing.
• Web container handle all process internally and client
or browser is not involved.
• When forward method is called on requestdispatcher
object we pass request and response objects so our old
request object is present on new resource which is
going to process our request.
hSenid Lanka: Java Server Pages Presentation 30
forward() Cont.
• We cannot notice any change of the URL in browser
address bar.
• Faster than send redirect.
• When we redirect using forward and we want to use same
data in new resource we can use request.setAttribute()
as we have request object available.
hSenid Lanka: Java Server Pages Presentation 31
MVC – Model View Controller
• It is a design pattern that separates the business
logic, presentation logic and data.
• Model
 The back-end of the application.
 Can be legacy code or Java code (usually JavaBeans).
hSenid Lanka: Java Server Pages Presentation 32
• View
• The end user’s view (what does the end user see?).
• Mostly done using JSP.
• Controller
• Controls the overall flow of the application.
• Usually a servlet.
MVC Cont.
hSenid Lanka: Java Server Pages Presentation 33
(Client)
Browser
(Controller)
Servlet
(View)
JSP
(Model)
Java
Beans
Enterprise
Servers/
Data
sources
Request
Response
Application server
1
5
3
2
instantiate
4
hSenid Lanka: Java Server Pages Presentation 34
hSenid Lanka: Java Server Pages Presentation 35

More Related Content

Similar to JSP.pdf

Coursejspservlets00
Coursejspservlets00Coursejspservlets00
Coursejspservlets00
Rajesh Moorjani
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
Rajesh Moorjani
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
arya krazydude
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
JSP overview
JSP overviewJSP overview
JSP overview
Amisha Narsingani
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
Atul Giri
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
Arumugam90
 
JSP Part 1
JSP Part 1JSP Part 1
JSP Part 1
DeeptiJava
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Yoga Raja
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
MattMarino13
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
Sudha Hari Tech Solution Pvt ltd
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
SachinSingh217687
 
Core web application development
Core web application developmentCore web application development
Core web application development
Bahaa Farouk
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
Abhishek Kesharwani
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
Abhishek Kesharwani
 
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
 
14 mvc
14 mvc14 mvc
14 mvc
snopteck
 
Jsp
JspJsp

Similar to JSP.pdf (20)

Coursejspservlets00
Coursejspservlets00Coursejspservlets00
Coursejspservlets00
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
JSP overview
JSP overviewJSP overview
JSP overview
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
 
JSP Part 1
JSP Part 1JSP Part 1
JSP Part 1
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Core web application development
Core web application developmentCore web application development
Core web application development
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
 
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
 
14 mvc
14 mvc14 mvc
14 mvc
 
Jsp
JspJsp
Jsp
 

More from Arumugam90

Notes for AR.ppt
Notes for AR.pptNotes for AR.ppt
Notes for AR.ppt
Arumugam90
 
Unity Tutorial_Highlighted Notes.pdf
Unity Tutorial_Highlighted Notes.pdfUnity Tutorial_Highlighted Notes.pdf
Unity Tutorial_Highlighted Notes.pdf
Arumugam90
 
AUGMENTED REALITY.pptx
AUGMENTED REALITY.pptxAUGMENTED REALITY.pptx
AUGMENTED REALITY.pptx
Arumugam90
 
Introductiontokaryotyping.pptx
Introductiontokaryotyping.pptxIntroductiontokaryotyping.pptx
Introductiontokaryotyping.pptx
Arumugam90
 
ML
MLML
intro.ppt
intro.pptintro.ppt
intro.ppt
Arumugam90
 
Unit I_Computer Networks_2.ppt
Unit I_Computer Networks_2.pptUnit I_Computer Networks_2.ppt
Unit I_Computer Networks_2.ppt
Arumugam90
 
Unit_I_Computer Networks 4.pdf
Unit_I_Computer Networks 4.pdfUnit_I_Computer Networks 4.pdf
Unit_I_Computer Networks 4.pdf
Arumugam90
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
Arumugam90
 
Chapter16.ppt
Chapter16.pptChapter16.ppt
Chapter16.ppt
Arumugam90
 
Chapter15.ppt
Chapter15.pptChapter15.ppt
Chapter15.ppt
Arumugam90
 
HTTP, JSP, and AJAX.pdf
HTTP, JSP, and AJAX.pdfHTTP, JSP, and AJAX.pdf
HTTP, JSP, and AJAX.pdf
Arumugam90
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
Arumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
Arumugam90
 
JDBC.pdf
JDBC.pdfJDBC.pdf
JDBC.pdf
Arumugam90
 
DSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdfDSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdf
Arumugam90
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdf
Arumugam90
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
Arumugam90
 
I MSc CS CNS Day 1.pptx
I MSc CS CNS Day 1.pptxI MSc CS CNS Day 1.pptx
I MSc CS CNS Day 1.pptx
Arumugam90
 

More from Arumugam90 (20)

Notes for AR.ppt
Notes for AR.pptNotes for AR.ppt
Notes for AR.ppt
 
Unity Tutorial_Highlighted Notes.pdf
Unity Tutorial_Highlighted Notes.pdfUnity Tutorial_Highlighted Notes.pdf
Unity Tutorial_Highlighted Notes.pdf
 
AUGMENTED REALITY.pptx
AUGMENTED REALITY.pptxAUGMENTED REALITY.pptx
AUGMENTED REALITY.pptx
 
Introductiontokaryotyping.pptx
Introductiontokaryotyping.pptxIntroductiontokaryotyping.pptx
Introductiontokaryotyping.pptx
 
ML
MLML
ML
 
intro.ppt
intro.pptintro.ppt
intro.ppt
 
Unit I_Computer Networks_2.ppt
Unit I_Computer Networks_2.pptUnit I_Computer Networks_2.ppt
Unit I_Computer Networks_2.ppt
 
Unit_I_Computer Networks 4.pdf
Unit_I_Computer Networks 4.pdfUnit_I_Computer Networks 4.pdf
Unit_I_Computer Networks 4.pdf
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
 
Chapter16.ppt
Chapter16.pptChapter16.ppt
Chapter16.ppt
 
Chapter15.ppt
Chapter15.pptChapter15.ppt
Chapter15.ppt
 
HTTP, JSP, and AJAX.pdf
HTTP, JSP, and AJAX.pdfHTTP, JSP, and AJAX.pdf
HTTP, JSP, and AJAX.pdf
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
JDBC.pdf
JDBC.pdfJDBC.pdf
JDBC.pdf
 
DSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdfDSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdf
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdf
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
 
I MSc CS CNS Day 1.pptx
I MSc CS CNS Day 1.pptxI MSc CS CNS Day 1.pptx
I MSc CS CNS Day 1.pptx
 

Recently uploaded

Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
kuntobimo2016
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
g4dpvqap0
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
AlessioFois2
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Fernanda Palhano
 

Recently uploaded (20)

Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
 

JSP.pdf

  • 1. hSenid Lanka: Java Server Pages Presentation  Introduction to JSP  Introduction to Servlet  JSP vs Servlet  Architecture of JSP  Life Cycle of a JSP Page  JSP Scripting Elements  JSP Directives  JSP Implicit Objects  Transferring Control of JSP  MVC in JSP 2
  • 2. hSenid Lanka: Java Server Pages Presentation  Demo o Create a JSP Page o Create a Servlet o Configure Servlet Using web.xml o Parse Data Between JSP & Servlet o Set Default Error Page 3
  • 3. hSenid Lanka: Java Server Pages Presentation • JSP is a server-side programming technology. • Developed by Sun Microsystems in 1999. • Fast way to create web pages to display dynamic data. • JSP page contains both static & dynamic data. 4
  • 4. hSenid Lanka: Java Server Pages Presentation • Helps to write web applications easily even with a less knowledge in Java. • Extension of a JSP page is .jsp or .jspx • Initially JSP was developed to replace servlet but now common practice is to use servlet and JSP together using MVC (model-view-controller) pattern. 5
  • 5. hSenid Lanka: Java Server Pages Presentation • Servlet is a server-side program. • Executes in a web server (eg: Tomcat). • Receives HTTP requests from users and returns HTTP responses. • Written in Java. • Runs on every platform that supports Java. • Supported my most popular web servers. 6
  • 6. hSenid Lanka: Java Server Pages Presentation 7 Relationship between JSP & Servlet • JSP is an interface on top of Servlets. • A JSP program is compiled into a Java servlet before execution. • Why JSP?  Easier to write than servlets  Designers can write HTML, programmers can write Java portions • Servlets came first, followed by JSP.
  • 7. hSenid Lanka: Java Server Pages Presentation 8 Advantages of Servlets • Performance  Get loaded upon first request  Multithreading  Each request runs in its own separate thread • Simplicity  Run inside controlled server environment  No specific client software is needed: Web browser is enough
  • 8. hSenid Lanka: Java Server Pages Presentation 9 Fig: JSP Processing
  • 9. hSenid Lanka: Java Server Pages Presentation 10 Client’s Computer Server 1.Browser requests HTML 7. Server sends HTML back to browser servlet servlet class 5.The servlet runs and generates HTML Java Engine 6. Java Engine sends HTML to server 2. Server sends requests to Java Engine 3. If needed, the Java Engine reads the .jsp file 4. The JSP is turned into a servlet, compiled, and loaded Bean JSP
  • 10. hSenid Lanka: Java Server Pages Presentation 11 • A JSP life cycle can be defined as the entire process from its creation till the destruction • The following are the paths followed by a JSP  Compilation has 3 steps  Parsing JSP  Turning the JSP into a servlet  Compiling the servlet  Initialization  Execution  Destroy
  • 11. hSenid Lanka: Java Server Pages Presentation 12 [destroy] jspDestroy() [Execution ] _jspService() [Intialization] jspInit() Request Response
  • 12. hSenid Lanka: Java Server Pages Presentation 13  There are three types of scripting elements in JSP, o Scriptlet tag o Expression tag o Declaration tag
  • 13. hSenid Lanka: Java Server Pages Presentation 14 Scriptlet Tag  In JSP, JAVA code can be written inside the JSP page using Scriptlet tag. Syntax: <% java source code %> Example: <html> <body> <% out.print(“Hello world…”); %> </body> </html>
  • 14. hSenid Lanka: Java Server Pages Presentation 15 Expression Tag  Code placed within expression tag is written to the output stream of the response. So, no need to write out.print() to write data. Syntax: <%= Statement %> Example: <html> <body> <%= “Hello world!” %> </body> </html> Note: Do not end statement with semicolon (;)
  • 15. hSenid Lanka: Java Server Pages Presentation 16 Declaration Tag  Used to declare fields and methods. The code written inside this tag is placed outside the service() method of auto generated servlet. So it doesn’t get memory at each request. Syntax: <%! Statement %> Example: <html> <body> <%! int data=60; %> <%= “Value is: “ + data %> </body> </html>
  • 16. hSenid Lanka: Java Server Pages Presentation 17  There are two types of JSP comment types that we are using.  Hidden Comments (JSP comments) o Visible only inside JSP page but not in the generated HTML page o Example: <%-- This is a hidden JSP comment --%>  Comments within HTML content o Comments to be generated inside the output HTML page o Example: <!-- Comment inside the generated HTML -->
  • 17. hSenid Lanka: Java Server Pages Presentation 18 • Directives are messages that tells the web container how to translate a JSP page into corresponding servlet. • Three types:  page directive  include directive  taglib directive • Syntax of JSP directives <%@ directive attribute=“value” %>
  • 18. hSenid Lanka: Java Server Pages Presentation 19 page directive • Defines attributes that apply to an entire JSP page. • Syntax: <%@ page attribute=“value” %> • Attributes : import, contentType, extends, info, buffer, language, autoFlush, session, pageEncoding, errorPage, isErrorPage
  • 19. hSenid Lanka: Java Server Pages Presentation 20 include directive • Includes the contents of any resource(may be jsp file, html file or text file. • It includes the original content of the included resources at page translation time. • Reusability is the advantage. • Syntax: <%@include file=“resourcename” %>
  • 20. hSenid Lanka: Java Server Pages Presentation 21 taglib directive • Used to define a tag library that defines many tags. • We use the TLD (Tag Library Descriptor) file to define the tags. • Syntax: <%@ taglib uri=“uriofthetaglibrary” prefix=“prefixoftaglibrary” %>
  • 21. hSenid Lanka: Java Server Pages Presentation 22  There are several objects that are automatically available in JSP called implicit objects. Variable Type out JspWriter request HTTPServletRequest response HTTPServletResponse config ServletConfig application ServletContext session HTTPSession pageContext PageContext page Object exception Throwable
  • 22. hSenid Lanka: Java Server Pages Presentation 23 out implicit object • For writing any data to the buffer, JSP provides an implicit object named out. Syntax: out.print(); request implicit object • Access to information associated with a request. This object is normally used in looking up parameter values and cookies. <% String str = request.getParameter(“uname”); %>
  • 23. hSenid Lanka: Java Server Pages Presentation 24 config implicit object • 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 • This object can be used to get configuration information from configuration file(web.xml). This variable information can be used for all JSP pages.
  • 24. hSenid Lanka: Java Server Pages Presentation 25 session implicit object • The Java developer can use this object to set, get or remove attribute or to get session information. pageContext implicit object • 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 exception implicit object • This object can be used to print the exception. But it can only be used in error pages.
  • 25. hSenid Lanka: Java Server Pages Presentation 26 • Transferring control explain how to redirect user to another page from JSP. There are two methods.  sendRedirect()  forward()
  • 26. hSenid Lanka: Java Server Pages Presentation 27 sendRedirect() • Request is transfer to another resource to different domain or different server for further processing. • Container transfers the request to client or browser so URL given inside the sendRedirect method is visible as a new request to the client. • When sendRedirect method calls, old request and response objects are lost because it is treated as new request by the browser.
  • 27. hSenid Lanka: Java Server Pages Presentation 28 sendRedirect() Cont. • We can notice the browser address bar URL will change. • This method is slower because it involves two tasks (requests).  Create a new request  Remove old request • If we need to pass data using this method, we may need to use session or pass data along with the URL.
  • 28. hSenid Lanka: Java Server Pages Presentation 29 forward() • Request is transfer to other resource within the same server for further processing. • Web container handle all process internally and client or browser is not involved. • When forward method is called on requestdispatcher object we pass request and response objects so our old request object is present on new resource which is going to process our request.
  • 29. hSenid Lanka: Java Server Pages Presentation 30 forward() Cont. • We cannot notice any change of the URL in browser address bar. • Faster than send redirect. • When we redirect using forward and we want to use same data in new resource we can use request.setAttribute() as we have request object available.
  • 30. hSenid Lanka: Java Server Pages Presentation 31 MVC – Model View Controller • It is a design pattern that separates the business logic, presentation logic and data. • Model  The back-end of the application.  Can be legacy code or Java code (usually JavaBeans).
  • 31. hSenid Lanka: Java Server Pages Presentation 32 • View • The end user’s view (what does the end user see?). • Mostly done using JSP. • Controller • Controls the overall flow of the application. • Usually a servlet. MVC Cont.
  • 32. hSenid Lanka: Java Server Pages Presentation 33 (Client) Browser (Controller) Servlet (View) JSP (Model) Java Beans Enterprise Servers/ Data sources Request Response Application server 1 5 3 2 instantiate 4
  • 33. hSenid Lanka: Java Server Pages Presentation 34
  • 34. hSenid Lanka: Java Server Pages Presentation 35