Pra*_*ker 13
page范围是指,可作为表示整个JSP页面,即,JSP对象只能从那里它被创建在同一页内访问的对象被认为是.
页面对象实际上是对象的直接同义词this.
注意:
页面范围和请求范围之间的主要区别(通常令人困惑)是,如果请求被转发到另一个JSP页面(其中请求范围属性可用),则页面范围属性将不再可用.
的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.
| 归档时间: |
|
| 查看次数: |
12136 次 |
| 最近记录: |