jsp中的页面范围

a L*_*ner 14 java jsp servlets

jsp中有以下范围:

页面范围

请求范围

会话范围

和应用范围.

我对页面范围感到困惑.谁能告诉我这个页面范围是什么?我没有在任何地方找到明确的定义.

Pra*_*ker 13

page范围是指,可作为表示整个JSP页面,即,JSP对象只能从那里它被创建在同一页内访问的对象被认为是.
页面对象实际上是对象的直接同义词this.
注意:

页面范围和请求范围之间的主要区别(通常令人困惑)是,如果请求被转发到另一个JSP页面(其中请求范围属性可用),则页面范围属性将不再可用.

  • 假设有一个页面包含另一个页面,那么翻译单元包括包含页面和包含页面,然后根据我在页面范围内的理解对象,翻译单元涉及的所有页面都可以使用。我错了吗? (2认同)

Pau*_*gas 8

page范围表示,除了被绑定到本地变量,豆对象应该被放置在javax.servlet.jsp.PageContext对象为当前请求的持续时间.

根据Allamaraju(2004):

JSP为JSP作者可以使用的对象定义了四个范围:

+-------------+------------------------------------------------------+
| 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.                        |
+-------------+------------------------------------------------------+

存储对象意味着servlet代码可以通过调用getAttribute预定义pageContext变量来访问它.由于每个页面和每个请求都有不同的PageContext对象,这表明bean不是共享的,因此将为每个请求创建一个新的bean.

JSP教程中查看更多内容.Servlet教程.初级和中级.


参考

Allamaraju,S.(2004).专业Java Servlets 2.3.加州伯克利:Apress.