SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Scope of JSP objects:
The availability of a JSP object for use from a particular place of the application is
defined as the scope of that JSP object. Every object created in a JSP page will have a
scope. Object scope in JSP is segregated into four parts and they are page, request,
session and application.

   •   page
       ‘page’ scope means, the JSP object can be accessed only from within the same
       page where it was created. The default scope for JSP objects created using
       <jsp:useBean> tag is page. JSP implicit objects out, exception, response,
       pageContext, config and page have ‘page’ scope.
   •   request
       A JSP object created using the ‘request’ scope can be accessed from any pages
       that serves that request. More than one page can serve a single request. The JSP
       object will be bound to the request object. Implicit object request has the ‘request’
       scope.
   •   session
       ’session’ scope means, the JSP object is accessible from pages that belong to the
       same session from where it was created. The JSP object that is created using the
       session scope is bound to the session object. Implicit object session has the
       ’session’ scope.
   •   application
       A JSP object created using the ‘application’ scope can be accessed from any
       pages across the application. The JSP object is bound to the application object.
       Implicit object application has the ‘application’ scope.

Saving Data in a Servlet

There are three places a servlet can save data for its processing - in the request, in the
session (if present), and in the servlet context (or application, which is shared by all
servlets and JSP pages in the context).
Data saved in the request is destroyed when the request is completed.
Data saved in the session is destroyed when the session is destroyed.
Data saved in the servlet context is destroyed when the servlet context is destroyed. Or
application is terminated.

Data is saved using a mechanism called attributes. An attribute is a key/value pair where
the key is a string and the value is any object. It is recommended that the key use the
reverse domain name convention (e.g., prefixed with com.mycompany) to minimize
unexpected collisions when integrating with third party modules.

Note: The three locations are identical to the three scopes -- request, session, and
application - - on a JSP page. So, if a servlet saves data in the request, the data will be
available on a JSP page in the request scope.

A JSP page-scoped value is simply implemented by a local variable in a servlet.
void setAttribute(String name,Object value);

Object getAttribute(String name);



This example saves and retrieves data in each of the three places:

     // Save and get a request-scoped value
     req.setAttribute(quot;com.mycompany.req-paramquot;, quot;req-valuequot;);
     Object value = req.getAttribute(quot;com.mycompany.req-paramquot;);

    // Save and get a session-scoped value
    HttpSession session = req.getSession(false);
    if (session != null) {
         session.setAttribute(quot;com.mycompany.session-paramquot;, quot;session-
valuequot;);
         value = session.getAttribute(quot;com.mycompany.session-paramquot;);
    }

    // Save and get an application-scoped value
    getServletContext().setAttribute(quot;com.mycompany.app-paramquot;, quot;app-
valuequot;);
    value = getServletContext().getAttribute(quot;com.mycompany.app-paramquot;);
The following example retrieves all attributes in a scope:
     // Get all request-scoped attributes
     java.util.Enumeration enum = req.getAttributeNames();
     for (; enum.hasMoreElements(); ) {
         // Get the name of the attribute
         String name = (String)enum.nextElement();

          // Get the value of the attribute
          Object value = req.getAttribute(name);
     }

     // Get all session-scoped attributes
     HttpSession session = req.getSession(false);
     if (session != null) {
         enum = session.getAttributeNames();
         for (; enum.hasMoreElements(); ) {
             // Get the name of the attribute
             String name = (String)enum.nextElement();

               // Get the value of the attribute
               Object value = session.getAttribute(name);
          }
     }

     // Get all application-scoped attributes
     enum = getServletContext().getAttributeNames();
     for (; enum.hasMoreElements(); ) {
         // Get the name of the attribute
         String name = (String)enum.nextElement();

          // Get the value of the attribute
Object value = getServletContext().getAttribute(name);
     }

Saving Data in a JSP Page

When a JSP page needs to save data for its processing, it must specify a location, called
the scope. There are four scopes available - page, request, session, and application. Page -
scoped data is accessible only within the JSP page and is destroyed when the page has
finished generating its output for the request. Request-scoped data is associated with the
request and destroyed when the request is completed. Session-scoped data is associated
with a session and destroyed when the session is destroyed. Application-scoped data is
associated with the web application and destroyed when the web application is destroyed.
Application-scoped data is not accessible to other web applications.

Data is saved using a mechanism called attributes. An attribute is a key/value pair where
the key is a string and the value is any object. It is recommended that the key use the
reverse domain name convention (e.g., prefixed with com.mycompany) to minimize
unexpected collisions when integrating with third party modules.




This example uses attributes to save and retrieve data in each of the four scopes:

     <%
        // Check if attribute has been set
        Object o = pageContext.getAttribute(quot;com.mycompany.name1quot;,
PageContext.PAGE_SCOPE);
        if (o == null) {
            // The attribute com.mycompany.name1 may not have a value
or may have the value null
        }

        // Save data
        pageContext.setAttribute(quot;com.mycompany.name1quot;,                quot;value0quot;);      //
PAGE_SCOPE is the default
        pageContext.setAttribute(quot;com.mycompany.name1quot;,                quot;value1quot;,
PageContext.PAGE_SCOPE);
        pageContext.setAttribute(quot;com.mycompany.name2quot;,                quot;value2quot;,
PageContext.REQUEST_SCOPE);
        pageContext.setAttribute(quot;com.mycompany.name3quot;,                quot;value3quot;,
PageContext.SESSION_SCOPE);
        pageContext.setAttribute(quot;com.mycompany.name4quot;,                quot;value4quot;,
PageContext.APPLICATION_SCOPE);
    %>

    <%-- Show the values --%>
    <%= pageContext.getAttribute(quot;com.mycompany.name1quot;) %> <%--
PAGE_SCOPE --%>
<%= pageContext.getAttribute(quot;com.mycompany.name1quot;,
PageContext.PAGE_SCOPE) %>
    <%= pageContext.getAttribute(quot;com.mycompany.name2quot;,
PageContext.REQUEST_SCOPE) %>
    <%= pageContext.getAttribute(quot;com.mycompany.name3quot;,
PageContext.SESSION_SCOPE) %>
    <%= pageContext.getAttribute(quot;com.mycompany.name4quot;,
PageContext.APPLICATION_SCOPE) %>

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Jsp
JspJsp
Jsp
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Jsp
JspJsp
Jsp
 
Jsp tutorial (1)
Jsp tutorial (1)Jsp tutorial (1)
Jsp tutorial (1)
 
Jsp lecture
Jsp lectureJsp lecture
Jsp lecture
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Jsp element
Jsp elementJsp element
Jsp element
 
JSP
JSPJSP
JSP
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 
Jsp slides
Jsp slidesJsp slides
Jsp slides
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Jsp(java server pages)
Jsp(java server pages)Jsp(java server pages)
Jsp(java server pages)
 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jsp
 
Jsp Slides
Jsp SlidesJsp Slides
Jsp Slides
 

Andere mochten auch

3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorialshiva404
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5phanleson
 
ASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMAashish Jain
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Peter R. Egli
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in javaAcp Jamod
 
Role of technology in business communication 2
Role of technology in business communication 2Role of technology in business communication 2
Role of technology in business communication 2mehwish88
 
Achieving competitive advantage with information systems
Achieving competitive advantage with information systemsAchieving competitive advantage with information systems
Achieving competitive advantage with information systemsProf. Othman Alsalloum
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJBPeter R. Egli
 

Andere mochten auch (20)

jsp tutorial
jsp tutorialjsp tutorial
jsp tutorial
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
ASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOM
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
INFORMATION TECHNOLOGY FOR BUSINESS
INFORMATION TECHNOLOGY FOR BUSINESSINFORMATION TECHNOLOGY FOR BUSINESS
INFORMATION TECHNOLOGY FOR BUSINESS
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Java bean
Java beanJava bean
Java bean
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Jsp
JspJsp
Jsp
 
Strategic use of information systems
Strategic use of information systemsStrategic use of information systems
Strategic use of information systems
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Role of technology in business communication 2
Role of technology in business communication 2Role of technology in business communication 2
Role of technology in business communication 2
 
Achieving competitive advantage with information systems
Achieving competitive advantage with information systemsAchieving competitive advantage with information systems
Achieving competitive advantage with information systems
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 

Ähnlich wie JSP Scope variable And Data Sharing

The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6...WebStackAcademy
 
ServletConfig & ServletContext
ServletConfig & ServletContextServletConfig & ServletContext
ServletConfig & ServletContextASHUTOSH TRIVEDI
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Jsp config implicit object
Jsp config implicit objectJsp config implicit object
Jsp config implicit objectchauhankapil
 
Remote code-with-expression-language-injection
Remote code-with-expression-language-injectionRemote code-with-expression-language-injection
Remote code-with-expression-language-injectionMickey Jack
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperVinay Kumar
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 AdvanceEmprovise
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 

Ähnlich wie JSP Scope variable And Data Sharing (20)

The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
Jsp
JspJsp
Jsp
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 6...
 
ServletConfig & ServletContext
ServletConfig & ServletContextServletConfig & ServletContext
ServletConfig & ServletContext
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Jsp config implicit object
Jsp config implicit objectJsp config implicit object
Jsp config implicit object
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
Remote code-with-expression-language-injection
Remote code-with-expression-language-injectionRemote code-with-expression-language-injection
Remote code-with-expression-language-injection
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paper
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 Advance
 
Jsp advance part i
Jsp advance part iJsp advance part i
Jsp advance part i
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
J2EE jsp_03
J2EE jsp_03J2EE jsp_03
J2EE jsp_03
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
User Interface
User InterfaceUser Interface
User Interface
 

Mehr von vikram singh

Mehr von vikram singh (20)

Agile
AgileAgile
Agile
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Web tech importants
Web tech importantsWeb tech importants
Web tech importants
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
2 4 Tree
2 4 Tree2 4 Tree
2 4 Tree
 
23 Tree Best Part
23 Tree   Best Part23 Tree   Best Part
23 Tree Best Part
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
jdbc
jdbcjdbc
jdbc
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
 
Xml
XmlXml
Xml
 
Dtd
DtdDtd
Dtd
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
 
Tutorial Solution
Tutorial SolutionTutorial Solution
Tutorial Solution
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Sample Report Format
Sample Report FormatSample Report Format
Sample Report Format
 

Kürzlich hochgeladen

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Kürzlich hochgeladen (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

JSP Scope variable And Data Sharing

  • 1. Scope of JSP objects: The availability of a JSP object for use from a particular place of the application is defined as the scope of that JSP object. Every object created in a JSP page will have a scope. Object scope in JSP is segregated into four parts and they are page, request, session and application. • page ‘page’ scope means, the JSP object can be accessed only from within the same page where it was created. The default scope for JSP objects created using <jsp:useBean> tag is page. JSP implicit objects out, exception, response, pageContext, config and page have ‘page’ scope. • request A JSP object created using the ‘request’ scope can be accessed from any pages that serves that request. More than one page can serve a single request. The JSP object will be bound to the request object. Implicit object request has the ‘request’ scope. • session ’session’ scope means, the JSP object is accessible from pages that belong to the same session from where it was created. The JSP object that is created using the session scope is bound to the session object. Implicit object session has the ’session’ scope. • application A JSP object created using the ‘application’ scope can be accessed from any pages across the application. The JSP object is bound to the application object. Implicit object application has the ‘application’ scope. Saving Data in a Servlet There are three places a servlet can save data for its processing - in the request, in the session (if present), and in the servlet context (or application, which is shared by all servlets and JSP pages in the context). Data saved in the request is destroyed when the request is completed. Data saved in the session is destroyed when the session is destroyed. Data saved in the servlet context is destroyed when the servlet context is destroyed. Or application is terminated. Data is saved using a mechanism called attributes. An attribute is a key/value pair where the key is a string and the value is any object. It is recommended that the key use the reverse domain name convention (e.g., prefixed with com.mycompany) to minimize unexpected collisions when integrating with third party modules. Note: The three locations are identical to the three scopes -- request, session, and application - - on a JSP page. So, if a servlet saves data in the request, the data will be available on a JSP page in the request scope. A JSP page-scoped value is simply implemented by a local variable in a servlet.
  • 2. void setAttribute(String name,Object value); Object getAttribute(String name); This example saves and retrieves data in each of the three places: // Save and get a request-scoped value req.setAttribute(quot;com.mycompany.req-paramquot;, quot;req-valuequot;); Object value = req.getAttribute(quot;com.mycompany.req-paramquot;); // Save and get a session-scoped value HttpSession session = req.getSession(false); if (session != null) { session.setAttribute(quot;com.mycompany.session-paramquot;, quot;session- valuequot;); value = session.getAttribute(quot;com.mycompany.session-paramquot;); } // Save and get an application-scoped value getServletContext().setAttribute(quot;com.mycompany.app-paramquot;, quot;app- valuequot;); value = getServletContext().getAttribute(quot;com.mycompany.app-paramquot;); The following example retrieves all attributes in a scope: // Get all request-scoped attributes java.util.Enumeration enum = req.getAttributeNames(); for (; enum.hasMoreElements(); ) { // Get the name of the attribute String name = (String)enum.nextElement(); // Get the value of the attribute Object value = req.getAttribute(name); } // Get all session-scoped attributes HttpSession session = req.getSession(false); if (session != null) { enum = session.getAttributeNames(); for (; enum.hasMoreElements(); ) { // Get the name of the attribute String name = (String)enum.nextElement(); // Get the value of the attribute Object value = session.getAttribute(name); } } // Get all application-scoped attributes enum = getServletContext().getAttributeNames(); for (; enum.hasMoreElements(); ) { // Get the name of the attribute String name = (String)enum.nextElement(); // Get the value of the attribute
  • 3. Object value = getServletContext().getAttribute(name); } Saving Data in a JSP Page When a JSP page needs to save data for its processing, it must specify a location, called the scope. There are four scopes available - page, request, session, and application. Page - scoped data is accessible only within the JSP page and is destroyed when the page has finished generating its output for the request. Request-scoped data is associated with the request and destroyed when the request is completed. Session-scoped data is associated with a session and destroyed when the session is destroyed. Application-scoped data is associated with the web application and destroyed when the web application is destroyed. Application-scoped data is not accessible to other web applications. Data is saved using a mechanism called attributes. An attribute is a key/value pair where the key is a string and the value is any object. It is recommended that the key use the reverse domain name convention (e.g., prefixed with com.mycompany) to minimize unexpected collisions when integrating with third party modules. This example uses attributes to save and retrieve data in each of the four scopes: <% // Check if attribute has been set Object o = pageContext.getAttribute(quot;com.mycompany.name1quot;, PageContext.PAGE_SCOPE); if (o == null) { // The attribute com.mycompany.name1 may not have a value or may have the value null } // Save data pageContext.setAttribute(quot;com.mycompany.name1quot;, quot;value0quot;); // PAGE_SCOPE is the default pageContext.setAttribute(quot;com.mycompany.name1quot;, quot;value1quot;, PageContext.PAGE_SCOPE); pageContext.setAttribute(quot;com.mycompany.name2quot;, quot;value2quot;, PageContext.REQUEST_SCOPE); pageContext.setAttribute(quot;com.mycompany.name3quot;, quot;value3quot;, PageContext.SESSION_SCOPE); pageContext.setAttribute(quot;com.mycompany.name4quot;, quot;value4quot;, PageContext.APPLICATION_SCOPE); %> <%-- Show the values --%> <%= pageContext.getAttribute(quot;com.mycompany.name1quot;) %> <%-- PAGE_SCOPE --%>
  • 4. <%= pageContext.getAttribute(quot;com.mycompany.name1quot;, PageContext.PAGE_SCOPE) %> <%= pageContext.getAttribute(quot;com.mycompany.name2quot;, PageContext.REQUEST_SCOPE) %> <%= pageContext.getAttribute(quot;com.mycompany.name3quot;, PageContext.SESSION_SCOPE) %> <%= pageContext.getAttribute(quot;com.mycompany.name4quot;, PageContext.APPLICATION_SCOPE) %>