SlideShare a Scribd company logo
1 of 26
Introduction to JSP
 JSP technology is used to create web application
just like Servlet technology.
 It can be thought of as an extension to Servlet
because it provides more functionality than
servlet such as expression language, JSTL, etc.
 A JSP page consists of HTML tags and JSP tags.
The JSP pages are easier to maintain than
Servlet because we can separate designing and
development.
 It provides some additional features such as
Expression Language, Custom Tags, etc.
Advantages of JSP over Servlet
 Extension to Servlet
 Easy to maintain
 Fast Development: No need to recompile and
redeploy
 Less code than Servlet
The Lifecycle of a JSP Page
 Translation of JSP Page
 Compilation of JSP Page
 Classloading (the classloader loads class file)
 Instantiation (Object of the Generated Servlet is
created).
 Initialization ( the container invokes jspInit() method).
 Request processing ( the container invokes
_jspService() method).
 Destroy ( the container invokes jspDestroy()
method).
 jspInit(), _jspService() and jspDestroy() are the life
cycle methods of JSP.
The Directory structure of JSP
Implicit Objects
 JSP Out
 JSP Request
 JSP Response
 JSP Config
 JSP Application
 JSP Session
 JSP PageContext
 JSP Page
 JSP Exception
Implicit Objects
 Out
For writing any data to the buffer, JSP provides an
implicit object named out. It is the object of JspWriter.
 Request
The JSP request is an implicit object of type
HttpServletRequest i.e. created for each jsp request
by the web container. It can be used to get request
information such as parameter, header information,
remote address, server name, server port, content
type, character encoding etc.
 JSP response implicit object
In JSP, response is an implicit object of type
HttpServletResponse. The instance of
HttpServletResponse is created by the web container
for each jsp request.
 Config
In JSP, config is an implicit object of type ServletConfig. This object
can be used to get
initialization parameter for a particular JSP page. The config object
is created by the web container for each jsp page.
<web-app>
<servlet>
<servlet-name>servlet</servlet-name>
<jsp-file>/welcome.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
application
 In JSP, application is an implicit object of
type ServletContext.
 The instance of ServletContext is created only
once by the web container when application or
project is deployed on the server.
 This object can be used to get initialization
parameter from configuaration file (web.xml). It
can also be used to get, set or remove attribute
from the application scope.
 This initialization parameter can be used by all jsp
pages.
pageContext
 Using this object you can find attribute, get
attribute, set attribute and remove attribute at any
of the below levels –
 JSP Page – Scope: PAGE_CONTEXT
 HTTP Request – Scope: REQUEST_CONTEXT
 HTTP Session – Scope: SESSION_CONTEXT
 Application Level – Scope:
APPLICATION_CONTEXT
Methods of pageContext
 Object findAttribute (String AttributeName)
 Object getAttribute (String AttributeName, int Scope)
Object obj = pageContext.getAttribute("BeginnersBook",
PageContext.SESSION_CONTEXT)
 void removeAttribute(String AttributeName, int Scope)
pageContext.removeAttribute(“MyAttr”, PageContext.
PAGE_CONTEXT);
 void setAttribute(String AttributeName, Object
AttributeValue, int Scope):
pageContext.setAttribute(“mydata”, “This is my data”,
PageContext. APPLICATION_CONTEXT);
Session object
 In JSP, session is an implicit object of type
HttpSession.The Java developer can use this
object to set,get or remove attribute or to get
session information.
Page object
 Page implicit variable holds the currently
executed servlet object for the corresponding jsp.
 Acts as this object for current jsp page.
Exception object
 Exception is the implicit object of the throwable
class.
 It is used for exception handling in JSP.
 The exception object can be only used in error
pages
Scripting Elements
 The scripting elements provides the ability to
insert java code inside the jsp. There are three
types of scripting elements:
 scriptlet
 expression
 Declaration
 comments
Scriplets
 Scriptlets are nothing but java code enclosed
within <% and %> tags.
 JSP container moves the statements enclosed in
it to _jspService() method while generating
servlet from JSP.
Declaration
 Declaration tag is a block of java code for
declaring class wide variables, methods and
classes.
 Whatever placed inside these tags gets initialized
during JSP initialization phase and has class
scope.
 JSP container keeps this code outside of the
service method (_jspService()) to make them
class level variables and methods.
 Syntax of declaration tag:
<%! Declaration %>
Expression
 Expression tag evaluates the expression placed in it,
converts the result into String and send the result
back to the client through response object.
 Basically it writes the result to the client(browser).
 Syntax
<%= expression %>
Example
<html>
<head>
<title>JSP expression tag example1</title>
</head>
<body> <%= 2+4*5 %>
</body>
</html>
JSP Directives
 Directives control the processing of an entire JSP
page. It gives directions to the server regarding
processing of a page.
 There are three types of Directives in JSP:
1) Page Directive
2) Include Directive
3) TagLib Directive
Page Directive
 There are several attributes, which are used along
with Page Directives and these are –
 Import
<%@page import="value"%>
Example
<%@page import="java.io.*%>
<%@page import="java.lang.*%>
Or
<%@page import="java.io.*, java.lang.*"%>
 Session
<%@ page session="false"%>
 isErrorPage
<%@ page isErrorPage="value"%>
 errorPage
<%@ page errorPage="value"%>
 ContentType
This attribute is used to set the content type of a JSP
page.
 isThreadSafe
It is used to allow multithreading which means only
single thread will execute the page code.
 extends
 Info
It provides a description to a JSP page. The string
specified in info will return when we will
call getServletInfo() method.
 Language
It specifies the scripting language( underlying
language) being used in the page.
 Autoflush
 Buffer
This attribute is used to specify the buffer size.
Include Directive
 Include directive is used to copy the content of
one JSP page to another. It’s like including the
code of one file into another.
<%@include file ="value"%>
Action tag
 Each JSP action tag is used to perform some
specific tasks.
 The action tags are used to control the flow
between pages and to use Java Bean.
 JSP Actions - jsp:forward , jsp:include,
jsp:useBean, jsp:setProperty and jsp:getProperty
jsp:forward action tag
 The jsp:forward action tag is used to forward the
request to another resource it may be jsp, html or
another resource.
 Syntax
<jsp:forward page="relativeURL | <%= expression
%>" />
jsp:include action tag
 The jsp:include action tag is used to include the
content of another resource it may be jsp, html or
servlet.
 Difference between include directive and include
action tag
include directive Include action tag
includes resource at
translation time.
includes resource at
request time.
better for static pages. better for dynamic pages.
 Workshop on Spring framework
 Date :18/06/2022
 Time : 8:30-10:30
 Mode : online
 Platform : MS-Teams

More Related Content

Similar to Introduction to JSP.pptx

3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorialshiva404
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsKaml Sah
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicIMC Institute
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSPGeethu Mohan
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGESKalpana T
 
anatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptxanatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptxSameenafathima4
 
Jsp interview questions by java training center
Jsp interview questions by java training centerJsp interview questions by java training center
Jsp interview questions by java training centerMaheshit Jtc
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...WebStackAcademy
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSbharathiv53
 

Similar to Introduction to JSP.pptx (20)

3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Java server pages
Java server pagesJava server pages
Java server pages
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
anatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptxanatomy of a jsp page & jsp syntax.pptx
anatomy of a jsp page & jsp syntax.pptx
 
JSP overview
JSP overviewJSP overview
JSP overview
 
Jsp interview questions by java training center
Jsp interview questions by java training centerJsp interview questions by java training center
Jsp interview questions by java training center
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
 
JSP
JSPJSP
JSP
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODS
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
Jsp1
Jsp1Jsp1
Jsp1
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 

Recently uploaded

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Recently uploaded (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

Introduction to JSP.pptx

  • 1. Introduction to JSP  JSP technology is used to create web application just like Servlet technology.  It can be thought of as an extension to Servlet because it provides more functionality than servlet such as expression language, JSTL, etc.  A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain than Servlet because we can separate designing and development.  It provides some additional features such as Expression Language, Custom Tags, etc.
  • 2. Advantages of JSP over Servlet  Extension to Servlet  Easy to maintain  Fast Development: No need to recompile and redeploy  Less code than Servlet
  • 3. The Lifecycle of a JSP Page
  • 4.  Translation of JSP Page  Compilation of JSP Page  Classloading (the classloader loads class file)  Instantiation (Object of the Generated Servlet is created).  Initialization ( the container invokes jspInit() method).  Request processing ( the container invokes _jspService() method).  Destroy ( the container invokes jspDestroy() method).  jspInit(), _jspService() and jspDestroy() are the life cycle methods of JSP.
  • 6. Implicit Objects  JSP Out  JSP Request  JSP Response  JSP Config  JSP Application  JSP Session  JSP PageContext  JSP Page  JSP Exception
  • 7. Implicit Objects  Out For writing any data to the buffer, JSP provides an implicit object named out. It is the object of JspWriter.  Request The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by the web container. It can be used to get request information such as parameter, header information, remote address, server name, server port, content type, character encoding etc.  JSP response implicit object In JSP, response is an implicit object of type HttpServletResponse. The instance of HttpServletResponse is created by the web container for each jsp request.
  • 8.  Config In JSP, config is an implicit object of type ServletConfig. This object can be used to get initialization parameter for a particular JSP page. The config object is created by the web container for each jsp page. <web-app> <servlet> <servlet-name>servlet</servlet-name> <jsp-file>/welcome.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>servlet</servlet-name> <url-pattern>/welcome</url-pattern> </servlet-mapping>
  • 9. application  In JSP, application is an implicit object of type ServletContext.  The instance of ServletContext is created only once by the web container when application or project is deployed on the server.  This object can be used to get initialization parameter from configuaration file (web.xml). It can also be used to get, set or remove attribute from the application scope.  This initialization parameter can be used by all jsp pages.
  • 10. pageContext  Using this object you can find attribute, get attribute, set attribute and remove attribute at any of the below levels –  JSP Page – Scope: PAGE_CONTEXT  HTTP Request – Scope: REQUEST_CONTEXT  HTTP Session – Scope: SESSION_CONTEXT  Application Level – Scope: APPLICATION_CONTEXT
  • 11. Methods of pageContext  Object findAttribute (String AttributeName)  Object getAttribute (String AttributeName, int Scope) Object obj = pageContext.getAttribute("BeginnersBook", PageContext.SESSION_CONTEXT)  void removeAttribute(String AttributeName, int Scope) pageContext.removeAttribute(“MyAttr”, PageContext. PAGE_CONTEXT);  void setAttribute(String AttributeName, Object AttributeValue, int Scope): pageContext.setAttribute(“mydata”, “This is my data”, PageContext. APPLICATION_CONTEXT);
  • 12. Session object  In JSP, session is an implicit object of type HttpSession.The Java developer can use this object to set,get or remove attribute or to get session information.
  • 13. Page object  Page implicit variable holds the currently executed servlet object for the corresponding jsp.  Acts as this object for current jsp page.
  • 14. Exception object  Exception is the implicit object of the throwable class.  It is used for exception handling in JSP.  The exception object can be only used in error pages
  • 15. Scripting Elements  The scripting elements provides the ability to insert java code inside the jsp. There are three types of scripting elements:  scriptlet  expression  Declaration  comments
  • 16. Scriplets  Scriptlets are nothing but java code enclosed within <% and %> tags.  JSP container moves the statements enclosed in it to _jspService() method while generating servlet from JSP.
  • 17. Declaration  Declaration tag is a block of java code for declaring class wide variables, methods and classes.  Whatever placed inside these tags gets initialized during JSP initialization phase and has class scope.  JSP container keeps this code outside of the service method (_jspService()) to make them class level variables and methods.  Syntax of declaration tag: <%! Declaration %>
  • 18. Expression  Expression tag evaluates the expression placed in it, converts the result into String and send the result back to the client through response object.  Basically it writes the result to the client(browser).  Syntax <%= expression %> Example <html> <head> <title>JSP expression tag example1</title> </head> <body> <%= 2+4*5 %> </body> </html>
  • 19. JSP Directives  Directives control the processing of an entire JSP page. It gives directions to the server regarding processing of a page.  There are three types of Directives in JSP: 1) Page Directive 2) Include Directive 3) TagLib Directive
  • 20. Page Directive  There are several attributes, which are used along with Page Directives and these are –  Import <%@page import="value"%> Example <%@page import="java.io.*%> <%@page import="java.lang.*%> Or <%@page import="java.io.*, java.lang.*"%>  Session <%@ page session="false"%>  isErrorPage <%@ page isErrorPage="value"%>  errorPage <%@ page errorPage="value"%>
  • 21.  ContentType This attribute is used to set the content type of a JSP page.  isThreadSafe It is used to allow multithreading which means only single thread will execute the page code.  extends  Info It provides a description to a JSP page. The string specified in info will return when we will call getServletInfo() method.  Language It specifies the scripting language( underlying language) being used in the page.  Autoflush  Buffer This attribute is used to specify the buffer size.
  • 22. Include Directive  Include directive is used to copy the content of one JSP page to another. It’s like including the code of one file into another. <%@include file ="value"%>
  • 23. Action tag  Each JSP action tag is used to perform some specific tasks.  The action tags are used to control the flow between pages and to use Java Bean.  JSP Actions - jsp:forward , jsp:include, jsp:useBean, jsp:setProperty and jsp:getProperty
  • 24. jsp:forward action tag  The jsp:forward action tag is used to forward the request to another resource it may be jsp, html or another resource.  Syntax <jsp:forward page="relativeURL | <%= expression %>" />
  • 25. jsp:include action tag  The jsp:include action tag is used to include the content of another resource it may be jsp, html or servlet.  Difference between include directive and include action tag include directive Include action tag includes resource at translation time. includes resource at request time. better for static pages. better for dynamic pages.
  • 26.  Workshop on Spring framework  Date :18/06/2022  Time : 8:30-10:30  Mode : online  Platform : MS-Teams