Page scope- scope in jsp

前端 未结 2 1435
盖世英雄少女心
盖世英雄少女心 2021-02-05 15:10

There are following scopes in jsp:

page scope

request scope

session scope

and application scope.

I am confused about page scope. Can any

相关标签:
2条回答
  • 2021-02-05 15:35

    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.

    0 讨论(0)
  • 2021-02-05 15:36

    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.

    0 讨论(0)
提交回复
热议问题