public class MockPageContext extends PageContext
PageContext
interface.
Only necessary for testing applications when testing custom JSP tags.
Note: Expects initialization via the constructor rather than via the
PageContext.initialize
method. Does not support writing to a
JspWriter, request dispatching, or handlePageException
calls.
APPLICATION, APPLICATION_SCOPE, CONFIG, EXCEPTION, OUT, PAGE, PAGE_SCOPE, PAGECONTEXT, REQUEST, REQUEST_SCOPE, RESPONSE, SESSION, SESSION_SCOPE
Constructor and Description |
---|
MockPageContext()
Create new MockPageContext with a default
MockServletContext ,
MockHttpServletRequest , MockHttpServletResponse ,
MockServletConfig . |
MockPageContext(ServletContext servletContext)
Create new MockPageContext with a default
MockHttpServletRequest ,
MockHttpServletResponse , MockServletConfig . |
MockPageContext(ServletContext servletContext,
HttpServletRequest request)
Create new MockPageContext with a MockHttpServletResponse,
MockServletConfig.
|
MockPageContext(ServletContext servletContext,
HttpServletRequest request,
HttpServletResponse response)
Create new MockPageContext with a MockServletConfig.
|
MockPageContext(ServletContext servletContext,
HttpServletRequest request,
HttpServletResponse response,
ServletConfig servletConfig)
Create new MockServletConfig.
|
getErrorData, pushBody
popBody, pushBody
public MockPageContext()
MockServletContext
,
MockHttpServletRequest
, MockHttpServletResponse
,
MockServletConfig
.public MockPageContext(@Nullable ServletContext servletContext)
MockHttpServletRequest
,
MockHttpServletResponse
, MockServletConfig
.servletContext
- the ServletContext that the JSP page runs in
(only necessary when actually accessing the ServletContext)public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request)
servletContext
- the ServletContext that the JSP page runs inrequest
- the current HttpServletRequest
(only necessary when actually accessing the request)public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response)
servletContext
- the ServletContext that the JSP page runs inrequest
- the current HttpServletRequestresponse
- the current HttpServletResponse
(only necessary when actually writing to the response)public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable ServletConfig servletConfig)
servletContext
- the ServletContext that the JSP page runs inrequest
- the current HttpServletRequestresponse
- the current HttpServletResponseservletConfig
- the ServletConfig (hardly ever accessed from within a tag)public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
initialize
in class PageContext
public void release()
release
in class PageContext
public void setAttribute(String name, @Nullable Object value)
setAttribute
in class JspContext
public void setAttribute(String name, @Nullable Object value, int scope)
setAttribute
in class JspContext
@Nullable public Object getAttribute(String name)
getAttribute
in class JspContext
@Nullable public Object getAttribute(String name, int scope)
getAttribute
in class JspContext
@Nullable public Object findAttribute(String name)
findAttribute
in class JspContext
public void removeAttribute(String name)
removeAttribute
in class JspContext
public void removeAttribute(String name, int scope)
removeAttribute
in class JspContext
public int getAttributesScope(String name)
getAttributesScope
in class JspContext
public Enumeration<String> getAttributeNames()
public Enumeration<String> getAttributeNamesInScope(int scope)
getAttributeNamesInScope
in class JspContext
public JspWriter getOut()
getOut
in class JspContext
@Deprecated public ExpressionEvaluator getExpressionEvaluator()
getExpressionEvaluator
in class JspContext
@Nullable public ELContext getELContext()
getELContext
in class JspContext
@Deprecated @Nullable public VariableResolver getVariableResolver()
getVariableResolver
in class JspContext
public HttpSession getSession()
getSession
in class PageContext
public Object getPage()
getPage
in class PageContext
public ServletRequest getRequest()
getRequest
in class PageContext
public ServletResponse getResponse()
getResponse
in class PageContext
@Nullable public Exception getException()
getException
in class PageContext
public ServletConfig getServletConfig()
getServletConfig
in class PageContext
public ServletContext getServletContext()
getServletContext
in class PageContext
public void forward(String path) throws ServletException, IOException
forward
in class PageContext
ServletException
IOException
public void include(String path) throws ServletException, IOException
include
in class PageContext
ServletException
IOException
public void include(String path, boolean flush) throws ServletException, IOException
include
in class PageContext
ServletException
IOException
public byte[] getContentAsByteArray()
public String getContentAsString() throws UnsupportedEncodingException
UnsupportedEncodingException
public void handlePageException(Exception ex) throws ServletException, IOException
handlePageException
in class PageContext
ServletException
IOException
public void handlePageException(Throwable ex) throws ServletException, IOException
handlePageException
in class PageContext
ServletException
IOException