SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Similar a 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 a 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
 

Último

20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 

Último (20)

20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 

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