Class PageContextImpl
- java.lang.Object
-
- jakarta.servlet.jsp.JspContext
-
- jakarta.servlet.jsp.PageContext
-
- org.apache.jasper.runtime.PageContextImpl
-
public class PageContextImpl extends PageContext
Implementation of the PageContext class from the JSP spec. Also doubles as a VariableResolver for the EL.- Author:
- Anil K. Vijendran, Larry Cable, Hans Bergsten, Pierre Delisle, Mark Roth, Jan Luehe, Jacob Hookom
-
-
Field Summary
-
Fields inherited from class jakarta.servlet.jsp.PageContext
APPLICATION, APPLICATION_SCOPE, CONFIG, EXCEPTION, OUT, PAGE, PAGE_SCOPE, PAGECONTEXT, REQUEST, REQUEST_SCOPE, RESPONSE, SESSION, SESSION_SCOPE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.void
forward(java.lang.String relativeUrlPath)
This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application.java.lang.Object
getAttribute(java.lang.String name)
Returns the object associated with the name in the page scope or null if not found.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.java.util.Enumeration<java.lang.String>
getAttributeNamesInScope(int scope)
Enumerate all the attributes in a given scope.int
getAttributesScope(java.lang.String name)
Get the scope where a given attribute is defined.ELContext
getELContext()
Obtain the ELContext for this JSPContext.java.lang.Exception
getException()
Returns the exception associated with this page context, if any.ExpressionEvaluator
getExpressionEvaluator()
Deprecated.JspWriter
getOut()
The current value of the out object (a JspWriter).java.lang.Object
getPage()
The current value of the page object (In a Servlet environment, this is an instance of jakarta.servlet.Servlet).ServletRequest
getRequest()
The current value of the request object (a ServletRequest).ServletResponse
getResponse()
The current value of the response object (a ServletResponse).ServletConfig
getServletConfig()
The ServletConfig instance.ServletContext
getServletContext()
The ServletContext instance.HttpSession
getSession()
The current value of the session object (an HttpSession).VariableResolver
getVariableResolver()
Deprecated.void
handlePageException(java.lang.Exception ex)
This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP.void
handlePageException(java.lang.Throwable t)
This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP.void
include(java.lang.String relativeUrlPath)
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread.void
include(java.lang.String relativeUrlPath, boolean flush)
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread.void
initialize(Servlet servlet, ServletRequest request, ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
The initialize method is called to initialize an uninitialized PageContext so that it may be used by a JSP Implementation class to service an incoming request and response within it's _jspService() method.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.static java.lang.Object
proprietaryEvaluate(java.lang.String expression, java.lang.Class<?> expectedType, PageContext pageContext, ProtectedFunctionMapper functionMap)
Proprietary method to evaluate EL expressions.BodyContent
pushBody()
Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext.JspWriter
pushBody(java.io.Writer writer)
Return a new JspWriter object that sends output to the provided Writer.void
release()
This method shall "reset" the internal state of a PageContext, releasing all internal references, and preparing the PageContext for potential reuse by a later invocation of initialize().void
removeAttribute(java.lang.String name)
Remove the object reference associated with the given name from all scopes.void
removeAttribute(java.lang.String name, int scope)
Remove the object reference associated with the specified name in the given scope.void
setAttribute(java.lang.String name, java.lang.Object attribute)
Register the name and value specified with page scope semantics.void
setAttribute(java.lang.String name, java.lang.Object o, int scope)
Register the name and value specified with appropriate scope semantics.-
Methods inherited from class jakarta.servlet.jsp.PageContext
getErrorData
-
-
-
-
Method Detail
-
initialize
public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) throws java.io.IOException
Description copied from class:jakarta.servlet.jsp.PageContext
The initialize method is called to initialize an uninitialized PageContext so that it may be used by a JSP Implementation class to service an incoming request and response within it's _jspService() method.
This method is typically called from JspFactory.getPageContext() in order to initialize state.
This method is required to create an initial JspWriter, and associate the "out" name in page scope with this newly created object.
This method should not be used by page or tag library authors.
- Specified by:
initialize
in classPageContext
- Parameters:
servlet
- The Servlet that is associated with this PageContextrequest
- The currently pending request for this Servletresponse
- The currently pending response for this ServleterrorPageURL
- The value of the errorpage attribute from the page directive or nullneedsSession
- The value of the session attribute from the page directivebufferSize
- The value of the buffer attribute from the page directiveautoFlush
- The value of the autoflush attribute from the page directive- Throws:
java.io.IOException
- during creation of JspWriter
-
release
public void release()
Description copied from class:jakarta.servlet.jsp.PageContext
This method shall "reset" the internal state of a PageContext, releasing all internal references, and preparing the PageContext for potential reuse by a later invocation of initialize(). This method is typically called from JspFactory.releasePageContext().
Subclasses shall envelope this method.
This method should not be used by page or tag library authors.
- Specified by:
release
in classPageContext
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from class:jakarta.servlet.jsp.JspContext
Returns the object associated with the name in the page scope or null if not found.- Specified by:
getAttribute
in classJspContext
- 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.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name, int scope)
Description copied from class:jakarta.servlet.jsp.JspContext
Return the object associated with the name in the specified scope or null if not found.- Specified by:
getAttribute
in classJspContext
- 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.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object attribute)
Description copied from class:jakarta.servlet.jsp.JspContext
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 )
.- Specified by:
setAttribute
in classJspContext
- Parameters:
name
- the name of the attribute to setattribute
- the value to associate with the name, or null if the attribute is to be removed from the page scope.
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object o, int scope)
Description copied from class:jakarta.servlet.jsp.JspContext
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 )
.- Specified by:
setAttribute
in classJspContext
- Parameters:
name
- the name of the attribute to seto
- 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
-
removeAttribute
public void removeAttribute(java.lang.String name, int scope)
Description copied from class:jakarta.servlet.jsp.JspContext
Remove the object reference associated with the specified name in the given scope. Does nothing if there is no such object.- Specified by:
removeAttribute
in classJspContext
- Parameters:
name
- The name of the object to remove.scope
- The scope where to look.
-
getAttributesScope
public int getAttributesScope(java.lang.String name)
Description copied from class:jakarta.servlet.jsp.JspContext
Get the scope where a given attribute is defined.- Specified by:
getAttributesScope
in classJspContext
- 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
-
findAttribute
public java.lang.Object findAttribute(java.lang.String name)
Description copied from class:jakarta.servlet.jsp.JspContext
Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.- Specified by:
findAttribute
in classJspContext
- Parameters:
name
- the name of the attribute to search for- Returns:
- the value associated or null
-
getAttributeNamesInScope
public java.util.Enumeration<java.lang.String> getAttributeNamesInScope(int scope)
Description copied from class:jakarta.servlet.jsp.JspContext
Enumerate all the attributes in a given scope.- Specified by:
getAttributeNamesInScope
in classJspContext
- 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
-
removeAttribute
public void removeAttribute(java.lang.String name)
Description copied from class:jakarta.servlet.jsp.JspContext
Remove the object reference associated with the given name from all scopes. Does nothing if there is no such object.- Specified by:
removeAttribute
in classJspContext
- Parameters:
name
- The name of the object to remove.
-
getOut
public JspWriter getOut()
Description copied from class:jakarta.servlet.jsp.JspContext
The current value of the out object (a JspWriter).- Specified by:
getOut
in classJspContext
- Returns:
- the current JspWriter stream being used for client response
-
getSession
public HttpSession getSession()
Description copied from class:jakarta.servlet.jsp.PageContext
The current value of the session object (an HttpSession).- Specified by:
getSession
in classPageContext
- Returns:
- the HttpSession for this PageContext or null
-
getServletConfig
public ServletConfig getServletConfig()
Description copied from class:jakarta.servlet.jsp.PageContext
The ServletConfig instance.- Specified by:
getServletConfig
in classPageContext
- Returns:
- the ServletConfig for this PageContext
-
getServletContext
public ServletContext getServletContext()
Description copied from class:jakarta.servlet.jsp.PageContext
The ServletContext instance.- Specified by:
getServletContext
in classPageContext
- Returns:
- the ServletContext for this PageContext
-
getRequest
public ServletRequest getRequest()
Description copied from class:jakarta.servlet.jsp.PageContext
The current value of the request object (a ServletRequest).- Specified by:
getRequest
in classPageContext
- Returns:
- The ServletRequest for this PageContext
-
getResponse
public ServletResponse getResponse()
Description copied from class:jakarta.servlet.jsp.PageContext
The current value of the response object (a ServletResponse).- Specified by:
getResponse
in classPageContext
- Returns:
- the ServletResponse for this PageContext
-
getException
public java.lang.Exception getException()
Returns the exception associated with this page context, if any.Added wrapping for Throwables to avoid ClassCastException: see Bugzilla 31171 for details.
- Specified by:
getException
in classPageContext
- Returns:
- The Exception associated with this page context, if any.
-
getPage
public java.lang.Object getPage()
Description copied from class:jakarta.servlet.jsp.PageContext
The current value of the page object (In a Servlet environment, this is an instance of jakarta.servlet.Servlet).- Specified by:
getPage
in classPageContext
- Returns:
- the Page implementation class instance associated with this PageContext
-
include
public void include(java.lang.String relativeUrlPath) throws ServletException, java.io.IOException
Description copied from class:jakarta.servlet.jsp.PageContext
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread. The output of the target resources processing of the request is written directly to the ServletResponse output stream.
The current JspWriter "out" for this JSP is flushed as a side-effect of this call, prior to processing the include.
If the relativeUrlPath begins with a "/" then the URL specified is calculated relative to the DOCROOT of the
ServletContext
for this JSP. If the path does not begin with a "/" then the URL specified is calculated relative to the URL of the request that was mapped to the calling JSP.It is only valid to call this method from a
Thread
executing within a_jspService(...)
method of a JSP.- Specified by:
include
in classPageContext
- Parameters:
relativeUrlPath
- specifies the relative URL path to the target resource to be included- Throws:
ServletException
- if the page that was forwarded to throws a ServletExceptionjava.io.IOException
- if an I/O error occurred while forwarding
-
include
public void include(java.lang.String relativeUrlPath, boolean flush) throws ServletException, java.io.IOException
Description copied from class:jakarta.servlet.jsp.PageContext
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread. The output of the target resources processing of the request is written directly to the current JspWriter returned by a call to getOut().
If flush is true, The current JspWriter "out" for this JSP is flushed as a side-effect of this call, prior to processing the include. Otherwise, the JspWriter "out" is not flushed.
If the relativeUrlPath begins with a "/" then the URL specified is calculated relative to the DOCROOT of the
ServletContext
for this JSP. If the path does not begin with a "/" then the URL specified is calculated relative to the URL of the request that was mapped to the calling JSP.It is only valid to call this method from a
Thread
executing within a_jspService(...)
method of a JSP.- Specified by:
include
in classPageContext
- Parameters:
relativeUrlPath
- specifies the relative URL path to the target resource to be includedflush
- True if the JspWriter is to be flushed before the include, or false if not.- Throws:
ServletException
- if the page that was forwarded to throws a ServletExceptionjava.io.IOException
- if an I/O error occurred while forwarding
-
getVariableResolver
@Deprecated public VariableResolver getVariableResolver()
Deprecated.Description copied from class:jakarta.servlet.jsp.JspContext
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.- Specified by:
getVariableResolver
in classJspContext
- Returns:
- A valid instance of a VariableResolver.
-
forward
public void forward(java.lang.String relativeUrlPath) throws ServletException, java.io.IOException
Description copied from class:jakarta.servlet.jsp.PageContext
This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application.
If the relativeUrlPath begins with a "/" then the URL specified is calculated relative to the DOCROOT of the
ServletContext
for this JSP. If the path does not begin with a "/" then the URL specified is calculated relative to the URL of the request that was mapped to the calling JSP.It is only valid to call this method from a
Thread
executing within a_jspService(...)
method of a JSP.Once this method has been called successfully, it is illegal for the calling
Thread
to attempt to modify theServletResponse
object. Any such attempt to do so, shall result in undefined behavior. Typically, callers immediately return from_jspService(...)
after calling this method.- Specified by:
forward
in classPageContext
- Parameters:
relativeUrlPath
- specifies the relative URL path to the target resource as described above- Throws:
ServletException
- if the page that was forwarded to throws a ServletExceptionjava.io.IOException
- if an I/O error occurred while forwarding
-
pushBody
public BodyContent pushBody()
Description copied from class:jakarta.servlet.jsp.PageContext
Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext.- Overrides:
pushBody
in classPageContext
- Returns:
- the new BodyContent
-
pushBody
public JspWriter pushBody(java.io.Writer writer)
Description copied from class:jakarta.servlet.jsp.JspContext
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
- Overrides:
pushBody
in classJspContext
- Parameters:
writer
- The Writer for the returned JspWriter to send output to.- Returns:
- a new JspWriter that writes to the given Writer.
-
popBody
public JspWriter popBody()
Description copied from class:jakarta.servlet.jsp.JspContext
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.- Overrides:
popBody
in classJspContext
- Returns:
- the saved JspWriter.
-
getExpressionEvaluator
@Deprecated public ExpressionEvaluator getExpressionEvaluator()
Deprecated.Provides programmatic access to the ExpressionEvaluator. The JSP Container must return a valid instance of an ExpressionEvaluator that can parse EL expressions.- Specified by:
getExpressionEvaluator
in classJspContext
- Returns:
- A valid instance of an ExpressionEvaluator.
-
handlePageException
public void handlePageException(java.lang.Exception ex) throws java.io.IOException, ServletException
Description copied from class:jakarta.servlet.jsp.PageContext
This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP. If forwarding is not possible (for example because the response has already been committed), an implementation dependent mechanism should be used to invoke the error page (e.g. "including" the error page instead).
If no error page is defined in the page, the exception should be rethrown so that the standard servlet error handling takes over.
A JSP implementation class shall typically clean up any local state prior to invoking this and will return immediately thereafter. It is illegal to generate any output to the client, or to modify any ServletResponse state after invoking this call.
This method is kept for backwards compatibility reasons. Newly generated code should use PageContext.handlePageException(Throwable).
- Specified by:
handlePageException
in classPageContext
- Parameters:
ex
- the exception to be handled- Throws:
java.io.IOException
- if an I/O error occurred while invoking the error pageServletException
- if an error occurs while invoking the error page- See Also:
PageContext.handlePageException(Throwable)
-
handlePageException
public void handlePageException(java.lang.Throwable t) throws java.io.IOException, ServletException
Description copied from class:jakarta.servlet.jsp.PageContext
This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP. If forwarding is not possible (for example because the response has already been committed), an implementation dependent mechanism should be used to invoke the error page (e.g. "including" the error page instead).
If no error page is defined in the page, the exception should be rethrown so that the standard servlet error handling takes over.
This method is intended to process an unhandled "page" level exception by redirecting the exception to either the specified error page for this JSP, or if none was specified, to perform some implementation dependent action.
A JSP implementation class shall typically clean up any local state prior to invoking this and will return immediately thereafter. It is illegal to generate any output to the client, or to modify any ServletResponse state after invoking this call.
- Specified by:
handlePageException
in classPageContext
- Parameters:
t
- the throwable to be handled- Throws:
java.io.IOException
- if an I/O error occurred while invoking the error pageServletException
- if an error occurs while invoking the error page- See Also:
PageContext.handlePageException(Exception)
-
proprietaryEvaluate
public static java.lang.Object proprietaryEvaluate(java.lang.String expression, java.lang.Class<?> expectedType, PageContext pageContext, ProtectedFunctionMapper functionMap) throws ELException
Proprietary method to evaluate EL expressions. XXX - This method should go away once the EL interpreter moves out of JSTL and into its own project. For now, this is necessary because the standard machinery is too slow.- Parameters:
expression
- The expression to be evaluatedexpectedType
- The expected resulting typepageContext
- The page contextfunctionMap
- Maps prefix and name to Method- Returns:
- The result of the evaluation
- Throws:
ELException
- If an error occurs during the evaluation
-
getELContext
public ELContext getELContext()
Description copied from class:jakarta.servlet.jsp.JspContext
Obtain the ELContext for this JSPContext. Each JSPContext has a dedicated ELCOntext.- Specified by:
getELContext
in classJspContext
- Returns:
- the ELContext for this JSPContext
-
-