SlideShare a Scribd company logo
1 of 34
Download to read offline
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 Introduction to Java Server Pages (JSP

Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Rajesh 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 usedarya krazydude
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jspAtul Giri
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdfArumugam90
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptxMattMarino13
 
Core web application development
Core web application developmentCore web application development
Core web application developmentBahaa Farouk
 
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
 

Similar to Introduction to Java Server Pages (JSP (20)

Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
 
Coursejspservlets00
Coursejspservlets00Coursejspservlets00
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 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
 
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.pptArumugam90
 
Unity Tutorial_Highlighted Notes.pdf
Unity Tutorial_Highlighted Notes.pdfUnity Tutorial_Highlighted Notes.pdf
Unity Tutorial_Highlighted Notes.pdfArumugam90
 
AUGMENTED REALITY.pptx
AUGMENTED REALITY.pptxAUGMENTED REALITY.pptx
AUGMENTED REALITY.pptxArumugam90
 
Introductiontokaryotyping.pptx
Introductiontokaryotyping.pptxIntroductiontokaryotyping.pptx
Introductiontokaryotyping.pptxArumugam90
 
Unit I_Computer Networks_2.ppt
Unit I_Computer Networks_2.pptUnit I_Computer Networks_2.ppt
Unit I_Computer Networks_2.pptArumugam90
 
Unit_I_Computer Networks 4.pdf
Unit_I_Computer Networks 4.pdfUnit_I_Computer Networks 4.pdf
Unit_I_Computer Networks 4.pdfArumugam90
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.pptArumugam90
 
HTTP, JSP, and AJAX.pdf
HTTP, JSP, and AJAX.pdfHTTP, JSP, and AJAX.pdf
HTTP, JSP, and AJAX.pdfArumugam90
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdfArumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdfArumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdfArumugam90
 
DSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdfDSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdfArumugam90
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdfArumugam90
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfArumugam90
 
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.pptxArumugam90
 

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

Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAbdelrhman abooda
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 

Recently uploaded (20)

Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 

Introduction to Java Server Pages (JSP

  • 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