Class MockPageContext
java.lang.Object
jakarta.servlet.jsp.JspContext
jakarta.servlet.jsp.PageContext
org.springframework.mock.web.MockPageContext
public class MockPageContext
extends jakarta.servlet.jsp.PageContext
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 jakarta.servlet.ServletContext servletContext) Create new MockPageContext with a defaultMockHttpServletRequest,MockHttpServletResponse,MockServletConfig.MockPageContext(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request) Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.MockPageContext(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response) Create new MockPageContext with a MockServletConfig.MockPageContext(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable jakarta.servlet.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[]@Nullable jakarta.el.ELContextjakarta.servlet.jsp.JspWritergetOut()getPage()jakarta.servlet.ServletRequestjakarta.servlet.ServletResponsejakarta.servlet.ServletConfigjakarta.servlet.ServletContextjakarta.servlet.http.HttpSessionvoidvoidvoidvoidvoidinitialize(jakarta.servlet.Servlet servlet, jakarta.servlet.ServletRequest request, jakarta.servlet.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 jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.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 jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.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 jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable jakarta.servlet.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(jakarta.servlet.Servlet servlet, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) - Specified by:
initializein classjakarta.servlet.jsp.PageContext
-
release
public void release()- Specified by:
releasein classjakarta.servlet.jsp.PageContext
-
setAttribute
-
setAttribute
-
getAttribute
-
getAttribute
-
findAttribute
-
removeAttribute
- Specified by:
removeAttributein classjakarta.servlet.jsp.JspContext
-
removeAttribute
- Specified by:
removeAttributein classjakarta.servlet.jsp.JspContext
-
getAttributesScope
- Specified by:
getAttributesScopein classjakarta.servlet.jsp.JspContext
-
getAttributeNames
-
getAttributeNamesInScope
- Specified by:
getAttributeNamesInScopein classjakarta.servlet.jsp.JspContext
-
getOut
public jakarta.servlet.jsp.JspWriter getOut()- Specified by:
getOutin classjakarta.servlet.jsp.JspContext
-
getELContext
- Specified by:
getELContextin classjakarta.servlet.jsp.JspContext
-
getSession
public jakarta.servlet.http.HttpSession getSession()- Specified by:
getSessionin classjakarta.servlet.jsp.PageContext
-
getPage
- Specified by:
getPagein classjakarta.servlet.jsp.PageContext
-
getRequest
public jakarta.servlet.ServletRequest getRequest()- Specified by:
getRequestin classjakarta.servlet.jsp.PageContext
-
getResponse
public jakarta.servlet.ServletResponse getResponse()- Specified by:
getResponsein classjakarta.servlet.jsp.PageContext
-
getException
-
getServletConfig
public jakarta.servlet.ServletConfig getServletConfig()- Specified by:
getServletConfigin classjakarta.servlet.jsp.PageContext
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()- Specified by:
getServletContextin classjakarta.servlet.jsp.PageContext
-
forward
- Specified by:
forwardin classjakarta.servlet.jsp.PageContext- Throws:
jakarta.servlet.ServletExceptionIOException
-
include
- Specified by:
includein classjakarta.servlet.jsp.PageContext- Throws:
jakarta.servlet.ServletExceptionIOException
-
include
public void include(String path, boolean flush) throws jakarta.servlet.ServletException, IOException - Specified by:
includein classjakarta.servlet.jsp.PageContext- Throws:
jakarta.servlet.ServletExceptionIOException
-
getContentAsByteArray
public byte[] getContentAsByteArray() -
getContentAsString
- Throws:
UnsupportedEncodingException
-
handlePageException
- Specified by:
handlePageExceptionin classjakarta.servlet.jsp.PageContext- Throws:
jakarta.servlet.ServletExceptionIOException
-
handlePageException
- Specified by:
handlePageExceptionin classjakarta.servlet.jsp.PageContext- Throws:
jakarta.servlet.ServletExceptionIOException
-