There are following scopes in jsp:
page scope
request scope
session scope
and application scope.
I am confused about page scope. Can any
The page
scope indicates that, in addition to
being bound to a local variable, the bean object should be placed in
the javax.servlet.jsp.PageContext object for the duration of the current request.
Acording to Allamaraju (2004):
JSP defines four scopes for the objects that can be used by the JSP authors:
+-------------+------------------------------------------------------+ | Scope | Description | +-------------+------------------------------------------------------+ | page | Objects can be accessed only within the JSP page | | | in which they are referenced. | +-------------+------------------------------------------------------+ | request | Objects can be accessed within all the pages that | | | serve the current request. These include pages | | | that are forwarded to, and included in, the original | | | JSP page to which the request was routed. | +-------------+------------------------------------------------------+ | session | Objects can only be accessed within the JSP pages | | | accessed within the session for which the objects | | | are defined. | +-------------+------------------------------------------------------+ | application | Application scope objects can be accessed by all | | | JSP pages in a given context. | +-------------+------------------------------------------------------+
Storing the object there means that servlet code can access it by
calling getAttribute
on the predefined pageContext
variable. Since every page and every request has a different PageContext
object, this indicates that the bean is not shared and thus a new bean will be created for each
request.
See more in JSP Tutorial. Servlet Tutorial. Beginning and Intermediate-Level.
References
Allamaraju, S. (2004). Professional Java Servlets 2.3. Berkeley, Calif: Apress.
page
scope means, it can be thought of as an object that represents the entire JSP page,i.e. the JSP object can be accessed only from within the same page where it was created.
The page object is really a direct synonym for the this
object.
Note:
The main difference between page scope and request scope(often confusing ) is that page scope attributes are no longer available if the request is forwarded to another JSP page where as request scope attributes are available.