Class JspContext
- java.lang.Object
-
- jakarta.servlet.jsp.JspContext
-
- Direct Known Subclasses:
PageContext
public abstract class JspContext extends java.lang.Object
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()
andpopBody()
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()
andgetAttributeNamesInScope()
.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
Constructors Constructor Description JspContext()
Sole constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract java.lang.Object
findAttribute(java.lang.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.abstract java.lang.Object
getAttribute(java.lang.String name)
Returns the object associated with the name in the page scope or null if not found.abstract java.lang.Object
getAttribute(java.lang.String name, int scope)
Return the object associated with the name in the specified scope or null if not found.abstract java.util.Enumeration<java.lang.String>
getAttributeNamesInScope(int scope)
Enumerate all the attributes in a given scope.abstract int
getAttributesScope(java.lang.String name)
Get the scope where a given attribute is defined.abstract jakarta.el.ELContext
getELContext()
Obtain the ELContext for this JSPContext.abstract ExpressionEvaluator
getExpressionEvaluator()
Deprecated.As of JSP 2.1, replaced by JspApplicationContext.getExpressionFactory()abstract JspWriter
getOut()
The current value of the out object (a JspWriter).abstract VariableResolver
getVariableResolver()
Deprecated.As of JSP 2.1, replaced by jakarta.el.ELContext.getELResolver() which can be obtained by jspContext.getELContext().getELResolver()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.JspWriter
pushBody(java.io.Writer writer)
Return a new JspWriter object that sends output to the provided Writer.abstract void
removeAttribute(java.lang.String name)
Remove the object reference associated with the given name from all scopes.abstract void
removeAttribute(java.lang.String name, int scope)
Remove the object reference associated with the specified name in the given scope.abstract void
setAttribute(java.lang.String name, java.lang.Object value)
Register the name and value specified with page scope semantics.abstract void
setAttribute(java.lang.String name, java.lang.Object value, int scope)
Register the name and value specified with appropriate scope semantics.
-
-
-
Method Detail
-
setAttribute
public abstract void setAttribute(java.lang.String name, java.lang.Object value)
Register the name and value specified with page scope semantics. If the value passed in isnull
, this has the same effect as callingremoveAttribute( name, PageContext.PAGE_SCOPE )
.- Parameters:
name
- the name of the attribute to setvalue
- the value to associate with the name, or null if the attribute is to be removed from the page scope.- Throws:
java.lang.NullPointerException
- if the name is null
-
setAttribute
public abstract void setAttribute(java.lang.String name, java.lang.Object value, int scope)
Register the name and value specified with appropriate scope semantics. If the value passed in isnull
, this has the same effect as callingremoveAttribute( name, scope )
.- Parameters:
name
- the name of the attribute to setvalue
- 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:
java.lang.NullPointerException
- if the name is nulljava.lang.IllegalArgumentException
- if the scope is invalidjava.lang.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.
-
getAttribute
public abstract java.lang.Object getAttribute(java.lang.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:
java.lang.NullPointerException
- if the name is null
-
getAttribute
public abstract java.lang.Object getAttribute(java.lang.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 setscope
- 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:
java.lang.NullPointerException
- if the name is nulljava.lang.IllegalArgumentException
- if the scope is invalidjava.lang.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.
-
findAttribute
public abstract java.lang.Object findAttribute(java.lang.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:
java.lang.NullPointerException
- if the name is null
-
removeAttribute
public abstract void removeAttribute(java.lang.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:
java.lang.NullPointerException
- if the name is null
-
removeAttribute
public abstract void removeAttribute(java.lang.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:
java.lang.IllegalArgumentException
- if the scope is invalidjava.lang.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.java.lang.NullPointerException
- if the name is null
-
getAttributesScope
public abstract int getAttributesScope(java.lang.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:
java.lang.NullPointerException
- if the name is null
-
getAttributeNamesInScope
public abstract java.util.Enumeration<java.lang.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:
java.lang.IllegalArgumentException
- if the scope is invalidjava.lang.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.
-
getOut
public abstract JspWriter getOut()
The current value of the out object (a JspWriter).- Returns:
- the current JspWriter stream being used for client response
-
getExpressionEvaluator
@Deprecated 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
-
getELContext
public abstract jakarta.el.ELContext getELContext()
Obtain the ELContext for this JSPContext. Each JSPContext has a dedicated ELCOntext.- Returns:
- the ELContext for this JSPContext
-
getVariableResolver
@Deprecated public abstract VariableResolver getVariableResolver()
Deprecated.As of JSP 2.1, replaced by jakarta.el.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
-
pushBody
public JspWriter pushBody(java.io.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
-
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.
-
-