Class MockPageContext
java.lang.Object
jakarta.servlet.jsp.JspContext
jakarta.servlet.jsp.PageContext
org.springframework.mock.web.MockPageContext
Mock implementation of the 
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.
- Since:
 - 1.0.2
 - Author:
 - Juergen Hoeller
 
- 
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 - 
Constructor Summary
ConstructorsConstructorDescriptionCreate new MockPageContext with a defaultMockServletContext,MockHttpServletRequest,MockHttpServletResponse,MockServletConfig.MockPageContext(@Nullable ServletContext servletContext) Create new MockPageContext with a defaultMockHttpServletRequest,MockHttpServletResponse,MockServletConfig.MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request) Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response) Create new MockPageContext with a MockServletConfig.MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable ServletConfig servletConfig) Create new MockServletConfig. - 
Method Summary
Modifier and TypeMethodDescriptionfindAttribute(String name) voidgetAttribute(String name) getAttribute(String name, int scope) getAttributeNamesInScope(int scope) intgetAttributesScope(String name) byte[]getOut()getPage()voidvoidvoidvoidvoidinitialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) voidrelease()voidremoveAttribute(String name) voidremoveAttribute(String name, int scope) voidsetAttribute(String name, @Nullable Object value) voidsetAttribute(String name, @Nullable Object value, int scope) Methods inherited from class jakarta.servlet.jsp.PageContext
getErrorData, pushBodyMethods inherited from class jakarta.servlet.jsp.JspContext
popBody, pushBody 
- 
Constructor Details
- 
MockPageContext
public MockPageContext()Create new MockPageContext with a defaultMockServletContext,MockHttpServletRequest,MockHttpServletResponse,MockServletConfig. - 
MockPageContext
Create new MockPageContext with a defaultMockHttpServletRequest,MockHttpServletResponse,MockServletConfig.- Parameters:
 servletContext- the ServletContext that the JSP page runs in (only necessary when actually accessing the ServletContext)
 - 
MockPageContext
public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request) Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.- Parameters:
 servletContext- the ServletContext that the JSP page runs inrequest- the current HttpServletRequest (only necessary when actually accessing the request)
 - 
MockPageContext
public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response) Create new MockPageContext with a MockServletConfig.- Parameters:
 servletContext- the ServletContext that the JSP page runs inrequest- the current HttpServletRequestresponse- the current HttpServletResponse (only necessary when actually writing to the response)
 - 
MockPageContext
public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable ServletConfig servletConfig) Create new MockServletConfig.- Parameters:
 servletContext- the ServletContext that the JSP page runs inrequest- the current HttpServletRequestresponse- the current HttpServletResponseservletConfig- the ServletConfig (hardly ever accessed from within a tag)
 
 - 
 - 
Method Details
- 
initialize
public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) - Specified by:
 initializein classPageContext
 - 
release
public void release()- Specified by:
 releasein classPageContext
 - 
setAttribute
- Specified by:
 setAttributein classJspContext
 - 
setAttribute
- Specified by:
 setAttributein classJspContext
 - 
getAttribute
- Specified by:
 getAttributein classJspContext
 - 
getAttribute
- Specified by:
 getAttributein classJspContext
 - 
findAttribute
- Specified by:
 findAttributein classJspContext
 - 
removeAttribute
- Specified by:
 removeAttributein classJspContext
 - 
removeAttribute
- Specified by:
 removeAttributein classJspContext
 - 
getAttributesScope
- Specified by:
 getAttributesScopein classJspContext
 - 
getAttributeNames
 - 
getAttributeNamesInScope
- Specified by:
 getAttributeNamesInScopein classJspContext
 - 
getOut
- Specified by:
 getOutin classJspContext
 - 
getELContext
- Specified by:
 getELContextin classJspContext
 - 
getSession
- Specified by:
 getSessionin classPageContext
 - 
getPage
- Specified by:
 getPagein classPageContext
 - 
getRequest
- Specified by:
 getRequestin classPageContext
 - 
getResponse
- Specified by:
 getResponsein classPageContext
 - 
getException
- Specified by:
 getExceptionin classPageContext
 - 
getServletConfig
- Specified by:
 getServletConfigin classPageContext
 - 
getServletContext
- Specified by:
 getServletContextin classPageContext
 - 
forward
- Specified by:
 forwardin classPageContext- Throws:
 ServletExceptionIOException
 - 
include
- Specified by:
 includein classPageContext- Throws:
 ServletExceptionIOException
 - 
include
- Specified by:
 includein classPageContext- Throws:
 ServletExceptionIOException
 - 
getContentAsByteArray
public byte[] getContentAsByteArray() - 
getContentAsString
- Throws:
 UnsupportedEncodingException
 - 
handlePageException
- Specified by:
 handlePageExceptionin classPageContext- Throws:
 ServletExceptionIOException
 - 
handlePageException
- Specified by:
 handlePageExceptionin classPageContext- Throws:
 ServletExceptionIOException
 
 -