• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regarding scope level

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two questions..
1. what is page level scope?
2. Can we access two different level attributes using a single object? Suppose that I have Session level object, can I use this object to get or set "request level" attribute because "session level" has broader scope (some thing like that) when compared to request level. Ofcourse, obviously we can use this to manipulate session level attribute.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Anything in page scope will be availabe in the page only. Which means that once the jsp will be displayed, the variable will be gone.
2. I don't quite understand the question. But you can put anything anywhere, so there should be no problem
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Page Scope is the smallest scope, and is a representation of the PageContext object for your JSP. Each JSP has it's own page scope, so objects in the page scope of one JSP are not accessible to other JSPs. This is sorta like making a private variable in Java.

Request scope is the next smallest scope, and is represented with the JSP's request object. All JSPs and servlets that share a request share the request scope. For example, if I have a JSP that forwards to another page, and that second page includes a third JSP page, then all three pages are in the same request, and can share objects through the request scope. A special note here, is the response.redirect(), will create a new request, unlike forwards and includes. Also note, a new request is made every time the user gets a new page, be it by clicking a link, a button, or some JavaScript call.

Session scope is the next lowest scope, represented by an HttpSession object. All requests from the same user are in the same session (unless you or they make it otherwise). Each user has his own session. If you want data to be referred to through multiple pages, after each page is displayed and the user requests a new page, then store the information in the session. Note, in order for sessions ot work, the user must have cookies on, or you must re-write the URLs. Take a look for maintaining sessions for more help on that.

The widest scope is the application scope, represented by the ServletContext object. All users share the same values of the application scope, as there is only one made for the web application. If you have some static material that all users should be able to access, then put it in the application, but be carefull. Each user will see the changes other users make, and certain threading issues can occur if not handled properly. So application scope is usually best used for Read-Only data.
 
Chandra Indukuri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
suppose that i have an attribute in the application scope. Now, can I use PageContext object, which has page scope, to access the application attribute?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The pageContext has methods to access all the other scopes.

In fact, pageContext is how the page accesses just about everything. That's why it's called the Page Context.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic