JspContext (Java EE 5)

Java EE API


javax.servlet.jsp Class JspContext

java.lang.Object
  extended by javax.servlet.jsp.JspContext
Direct Known Subclasses:
PageContext

public abstract class JspContext
extends Object

Extended by: PageContext

JspContext 充当 PageContext 类的基类,并抽象化不特定于 servlet 的所有信息。这允许在请求/响应 Servlet 上下文以外使用简单标记扩展。

JspContext 为页面/组件作者和页面实现者提供了许多工具,其中包括:

  • 管理各种范围名称空间的单个 API
  • 获取 JspWriter 以供输出的机制
  • 向脚本环境公开页面指令属性的机制

供容器生成的代码使用的方法

以下方法使嵌套管理的 JspWriter 流能够实现标记扩展:pushBody()popBody()

供 JSP 作者使用的方法

一些方法提供了对不同对象表示范围的统一访问。该实现必须使用与该范围对应的底层机制,因此信息可以在底层环境(例如 Servlet)与 JSP 页面之间来回传递。这些方法有:setAttribute()getAttribute()findAttribute()removeAttribute()getAttributesScope()getAttributeNamesInScope()

以下方法提供对隐式对象的便捷访问getOut()

以下方法提供对表达式语言计算器的编程访问getExpressionEvaluator()getVariableResolver()

英文文档:

JspContext serves as the base class for the PageContext class and abstracts all information that is not specific to servlets. This allows for Simple Tag Extensions to be used outside of the context of a request/response Servlet.

The JspContext provides a number of facilities to the page/component author and page implementor, including:

  • a single API to manage the various scoped namespaces
  • a mechanism to obtain the JspWriter for output
  • a mechanism to expose page directive attributes to the scripting environment

Methods Intended for Container Generated Code

The following methods enable the management of nested JspWriter streams to implement Tag Extensions: pushBody() and popBody()

Methods Intended for JSP authors

Some methods provide uniform access to the diverse objects representing scopes. The implementation must use the underlying machinery corresponding to that scope, so information can be passed back and forth between the underlying environment (e.g. Servlets) and JSP pages. The methods are: setAttribute(), getAttribute(), findAttribute(), removeAttribute(), getAttributesScope() and getAttributeNamesInScope().

The following methods provide convenient access to implicit objects: getOut()

The following methods provide programmatic access to the Expression Language evaluator: getExpressionEvaluator(), getVariableResolver()

Since:
JSP 2.0

Constructor Summary
 
Method Summary
abstract  Object
abstract  Object
abstract  Object
abstract  Enumeration<String>
abstract  int
abstract  ELContext
abstract  ExpressionEvaluator
abstract  JspWriter
abstract  VariableResolver
 JspWriter
 JspWriter
abstract  void
abstract  void
abstract  void
abstract  void
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public JspContext()
唯一的构造方法。(由子类构造方法调用,通常是隐式的)。
英文文档:

JspContext

public JspContext()
Sole constructor. (For invocation by subclass constructors, typically implicit.)

Method Detail

abstract public void setAttribute(String name, Object value)
注册使用页面范围语义指定的名称和值。如果传入的值为 null,则调用此方法与调用 removeAttribute( name, PageContext.PAGE_SCOPE ) 产生的效果相同。
name 要设置的属性的名称
value 与 name 关联的值,如果将从页面范围中移除该属性,则此参数为 null。
ThrowsNullPointerException: 如果名称为 null。
英文文档:

setAttribute

public abstract void setAttribute(String name,
                                  Object value)
Register the name and value specified with page scope semantics. If the value passed in is null, this has the same effect as calling removeAttribute( name, PageContext.PAGE_SCOPE ).

Parameters:
name - the name of the attribute to set
value - the value to associate with the name, or null if the attribute is to be removed from the page scope.
Throws:
NullPointerException - if the name is null

abstract public void setAttribute(String name, Object value, int scope)
注册使用适当范围语义指定的名称和值。如果传入的值为 null,则调用此方法与调用 removeAttribute( name, scope ) 产生的效果相同。
name 要设置的属性的名称
value 与 name 关联的对象,如果将从指定范围中移除该属性,则此参数为 null。
scope 与名称/对象关联的范围
ThrowsNullPointerException: 如果名称为 null。
ThrowsIllegalArgumentException: 如果 scope 有效
ThrowsIllegalStateException: 如果 scope 为 PageContext.SESSION_SCOPE,但请求的页面未参与会话,或者会话已经无效。
英文文档:

setAttribute

public abstract void setAttribute(String name,
                                  Object value,
                                  int scope)
Register the name and value specified with appropriate scope semantics. If the value passed in is null, this has the same effect as calling removeAttribute( name, scope ).

Parameters:
name - the name of the attribute to set
value - the object to associate with the name, or null if the attribute is to be removed from the specified scope.
scope - the scope with which to associate the name/object
Throws:
NullPointerException - if the name is null
IllegalArgumentException - if the scope is invalid
IllegalStateException - if the scope is PageContext.SESSION_SCOPE but the page that was requested does not participate in a session or the session has been invalidated.

abstract public Object getAttribute(String name)
返回与页面范围中的名称关联的对象,如果该对象不存在,则返回 null。
name 要获取的属性的名称
return 与页面范围中的名称关联的对象,如果该对象不存在,则返回 null。
ThrowsNullPointerException: 如果名称为 null。
英文文档:

getAttribute

public abstract Object getAttribute(String name)
Returns the object associated with the name in the page scope or null if not found.

Parameters:
name - the name of the attribute to get
Returns:
the object associated with the name in the page scope or null if not found.
Throws:
NullPointerException - if the name is null

abstract public Object getAttribute(String name, int scope)
返回与指定范围中的名称关联的对象,如果该对象不存在,则返回 null。
name 要设置的属性的名称
scope 与名称/对象关联的范围
return 与指定范围中的名称关联的对象,如果该对象不存在,则返回 null。
ThrowsNullPointerException: 如果名称为 null。
ThrowsIllegalArgumentException: 如果 scope 有效
ThrowsIllegalStateException: 如果 scope 为 PageContext.SESSION_SCOPE,但请求的页面未参与会话,或者会话已经无效。
英文文档:

getAttribute

public abstract Object getAttribute(String name,
                                    int scope)
Return the object associated with the name in the specified scope or null if not found.

Parameters:
name - the name of the attribute to set
scope - the scope with which to associate the name/object
Returns:
the object associated with the name in the specified scope or null if not found.
Throws:
NullPointerException - if the name is null
IllegalArgumentException - if the scope is invalid
IllegalStateException - if the scope is PageContext.SESSION_SCOPE but the page that was requested does not participate in a session or the session has been invalidated.

abstract public Object findAttribute(String name)
按顺序在页面、请求、会话(如果有效)和应用程序范围中搜索指定属性,并返回关联的值或 null。
name 要搜索的属性的名称
return 关联的值或 null
ThrowsNullPointerException: 如果名称为 null。
英文文档:

findAttribute

public abstract Object findAttribute(String name)
Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.

Parameters:
name - the name of the attribute to search for
Returns:
the value associated or null
Throws:
NullPointerException - if the name is null

abstract public void removeAttribute(String name)
从所有范围中移除与给定名称关联的对象引用。如果没有此类对象,则不执行任何操作。
name 要移除的对象的名称。
ThrowsNullPointerException: 如果名称为 null。
英文文档:

removeAttribute

public abstract void removeAttribute(String name)
Remove the object reference associated with the given name from all scopes. Does nothing if there is no such object.

Parameters:
name - The name of the object to remove.
Throws:
NullPointerException - if the name is null

abstract public void removeAttribute(String name, int scope)
移除给定范围中与指定名称关联的对象引用。如果没有此类对象,则不执行任何操作。
name 要移除的对象的名称。
scope 要查看的范围。
ThrowsIllegalArgumentException: 如果 scope 有效
ThrowsIllegalStateException: 如果 scope 为 PageContext.SESSION_SCOPE,但请求的页面未参与会话,或者会话已经无效。
ThrowsNullPointerException: 如果名称为 null。
英文文档:

removeAttribute

public abstract void removeAttribute(String name,
                                     int scope)
Remove the object reference associated with the specified name in the given scope. Does nothing if there is no such object.

Parameters:
name - The name of the object to remove.
scope - The scope where to look.
Throws:
IllegalArgumentException - if the scope is invalid
IllegalStateException - if the scope is PageContext.SESSION_SCOPE but the page that was requested does not participate in a session or the session has been invalidated.
NullPointerException - if the name is null

abstract public int getAttributesScope(String name)
获取在其中定义给定属性的范围。
name 为其返回范围的属性的名称
return 与指定名称关联的对象的范围或 0
ThrowsNullPointerException: 如果名称为 null。
英文文档:

getAttributesScope

public abstract int getAttributesScope(String name)
Get the scope where a given attribute is defined.

Parameters:
name - the name of the attribute to return the scope for
Returns:
the scope of the object associated with the name specified or 0
Throws:
NullPointerException - if the name is null

abstract public java.util.Enumeration<E> getAttributeNamesInScope(int scope)
枚举给定范围中的所有属性。
scope 为其枚举所有属性的范围
return 指定范围中所有属性名称 (java.lang.String) 的枚举
ThrowsIllegalArgumentException: 如果 scope 有效
ThrowsIllegalStateException: 如果 scope 为 PageContext.SESSION_SCOPE,但请求的页面未参与会话,或者会话已经无效。
英文文档:

getAttributeNamesInScope

public abstract Enumeration<String> getAttributeNamesInScope(int scope)
Enumerate all the attributes in a given scope.

Parameters:
scope - the scope to enumerate all the attributes for
Returns:
an enumeration of names (java.lang.String) of all the attributes the specified scope
Throws:
IllegalArgumentException - if the scope is invalid
IllegalStateException - if the scope is PageContext.SESSION_SCOPE but the page that was requested does not participate in a session or the session has been invalidated.

abstract public JspWriter getOut()
out 对象(一个 JspWriter)的当前值。
return 正用于客户端响应的当前 JspWriter 流
英文文档:

getOut

public abstract JspWriter getOut()
The current value of the out object (a JspWriter).

Returns:
the current JspWriter stream being used for client response

abstract public ExpressionEvaluator getExpressionEvaluator()
提供对 ExpressionEvaluator 的编程访问。JSP 容器必须返回能解析 EL 表达式的有效 ExpressionEvaluator 实例。
return 有效的 ExpressionEvaluator 实例。
since2.0
英文文档:

getExpressionEvaluator

public abstract ExpressionEvaluator getExpressionEvaluator()
Deprecated. As of JSP 2.1, replaced by JspApplicationContext.getExpressionFactory()

Provides programmatic access to the ExpressionEvaluator. The JSP Container must return a valid instance of an ExpressionEvaluator that can parse EL expressions.

Returns:
A valid instance of an ExpressionEvaluator.
Since:
JSP 2.0

abstract public VariableResolver getVariableResolver()
返回一个 VariableResolver 实例,该实例提供对 JSP 规范中指定的隐式对象的访问,该对象是使用此 JspContext 以上下文对象的形式指定的。
return 有效的 VariableResolver 实例。
since2.0
英文文档:

getVariableResolver

public abstract VariableResolver getVariableResolver()
Deprecated. As of JSP 2.1, replaced by ELContext.getELResolver(), which can be obtained by jspContext.getELContext().getELResolver().

Returns an instance of a VariableResolver that provides access to the implicit objects specified in the JSP specification using this JspContext as the context object.

Returns:
A valid instance of a VariableResolver.
Since:
JSP 2.0

英文文档:

getELContext

public abstract ELContext getELContext()
Returns the ELContext associated with this JspContext.

The ELContext is created lazily and is reused if it already exists. There is a new ELContext for each JspContext.

The ELContext must contain the ELResolver described in the JSP specification (and in the javadocs for JspApplicationContext.addELResolver(javax.el.ELResolver)).

Returns:
The ELContext associated with this JspContext.
Since:
JSP 2.1

public JspWriter pushBody(java.io.Writer writer)
返回将输出发送到提供的 Writer 的新 JspWriter 对象。保存当前的 "out" JspWriter,并更新 JspContext 的页面范围属性名称空间中的 "out" 属性的值。

返回的 JspWriter 必须实现所有方法,并且表现得就像它未被缓冲一样。更确切地说:

  • clear() 必须抛出 IOException
  • clearBuffer() 不执行任何操作
  • getBufferSize() 总是返回 0
  • getRemaining() 总是返回 0

writer 返回的 JspWriter 将输出发送到的 Writer。
return 写入给定 Writer 的新 JspWriter。
since2.0
英文文档:

pushBody

public JspWriter pushBody(Writer writer)
Return a new JspWriter object that sends output to the provided Writer. Saves the current "out" JspWriter, and updates the value of the "out" attribute in the page scope attribute namespace of the JspContext.

The returned JspWriter must implement all methods and behave as though it were unbuffered. More specifically:

  • clear() must throw an IOException
  • clearBuffer() does nothing
  • getBufferSize() always returns 0
  • getRemaining() always returns 0

Parameters:
writer - The Writer for the returned JspWriter to send output to.
Returns:
a new JspWriter that writes to the given Writer.
Since:
JSP 2.0

public JspWriter popBody()
返回匹配的 pushBody() 保存的以前的 JspWriter "out",并更新 JspContext 的页面范围属性名称空间中的 "out" 属性的值。
return 保存的 JspWriter。
英文文档:

popBody

public JspWriter popBody()
Return the previous JspWriter "out" saved by the matching pushBody(), and update the value of the "out" attribute in the page scope attribute namespace of the JspContext.

Returns:
the saved JspWriter.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!