Page scope- scope in jsp

前端 未结 2 1438
盖世英雄少女心
盖世英雄少女心 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.

提交回复
热议问题