Forums Register Login

regarding scope level

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
What are you doing? You are supposed to be reading this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1286 times.
Similar Threads
parameter vs attributes?
Is jsp:useBean scope='session' attribute is going to be deprecated?
setting attributes in the scopes
Related to Session and Request objects
In what ways can you pull something from the request?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:06:23.