File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes regarding scope level Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "regarding scope level" Watch "regarding scope level" New topic
Author

regarding scope level

Chandra Indukuri
Greenhorn

Joined: Jan 30, 2007
Posts: 4
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.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
hanumanth reddy
Ranch Hand

Joined: Jun 12, 2000
Posts: 118
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.


<a href="http://www.jobklub.com" target="_blank" rel="nofollow">http://www.jobklub.com</a><br /> 'Add Job To Life'
Chandra Indukuri
Greenhorn

Joined: Jan 30, 2007
Posts: 4
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding scope level