HttpServletRequest, HttpServletResponse, and the response PrintWriter are frequently accessed while also frequently updated by elements for capture. It is tedious to pass these objects around all over. Also, with the lambda scoping in Java 8, it is easy to use the wrong object from a different scope (and possibly capturing context).
Each context is intended to be established and used within a single servlet implementation. Do not assume correct management of PageContext between different pages, servlets, or files. If in doubt, skip this shortcut and pass explicit object references around.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
PageContext.PageContextCallableSkipE<V,
Ex extends Exception> static interface
static interface
static interface
static interface
static interface
PageContext.PageContextRunnableSkipEE<Ex1 extends Throwable,
Ex2 extends Throwable> -
Method Summary
Modifier and TypeMethodDescriptionstatic PrintWriter
getOut()
Gets the current response writer.static HttpServletRequest
Gets the current request.static HttpServletResponse
Gets the current response.static ServletContext
Gets the current servlet context.static <V> V
newPageContext
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallable<V> target) static void
newPageContext
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnable target) static <V> V
newPageContextSkip
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallableSkip<V> target) Establishes a new page context.static void
newPageContextSkip
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnableSkip target) Establishes a new page context.static <V,
Ex extends Exception>
VnewPageContextSkipE
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallableSkipE<V, Ex> target) static <Ex extends Throwable>
voidnewPageContextSkipE
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnableSkipE<Ex> target) newPageContextSkipEE
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallableSkipEE<V, Ex1, Ex2> target) newPageContextSkipEE
(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnableSkipEE<Ex1, Ex2> target)
-
Method Details
-
newPageContext
public static void newPageContext(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnable target) throws ServletException, IOException - Throws:
ServletException
IOException
-
newPageContext
public static <V> V newPageContext(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallable<V> target) throws ServletException, IOException - Throws:
ServletException
IOException
-
newPageContextSkip
public static void newPageContextSkip(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnableSkip target) throws ServletException, IOException, SkipPageException Establishes a new page context. This usually does not need to be done directly as creating a page will establish the starting page context. -
newPageContextSkip
public static <V> V newPageContextSkip(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallableSkip<V> target) throws ServletException, IOException, SkipPageException Establishes a new page context. This usually does not need to be done directly as creating a page will establish the starting page context. -
newPageContextSkipE
public static <Ex extends Throwable> void newPageContextSkipE(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnableSkipE<Ex> target) throws Ex, ServletException, IOException, SkipPageException - Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
Ex
ServletException
IOException
SkipPageException
-
newPageContextSkipE
public static <V,Ex extends Exception> V newPageContextSkipE(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallableSkipE<V, Ex> target) throws Ex, ServletException, IOException, SkipPageException- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
Ex
ServletException
IOException
SkipPageException
-
newPageContextSkipEE
public static <Ex1 extends Throwable,Ex2 extends Throwable> void newPageContextSkipEE(ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextRunnableSkipEE<Ex1, Ex2> target) throws Ex1, Ex2, ServletException, IOException, SkipPageException- Throws:
Ex1
Ex2
ServletException
IOException
SkipPageException
-
newPageContextSkipEE
public static <V,Ex1 extends Exception, V newPageContextSkipEEEx2 extends Exception> (ServletContext newServletContext, HttpServletRequest newRequest, HttpServletResponse newResponse, PageContext.PageContextCallableSkipEE<V, Ex1, throws Ex1, Ex2, ServletException, IOException, SkipPageExceptionEx2> target) - Throws:
Ex1
Ex2
ServletException
IOException
SkipPageException
-
getServletContext
Gets the current servlet context.- Throws:
IllegalStateException
- if no context set
-
getRequest
Gets the current request.- Throws:
IllegalStateException
- if no context set
-
getResponse
Gets the current response.- Throws:
IllegalStateException
- if no context set
-
getOut
Gets the current response writer.- Throws:
IllegalStateException
- if no context setIOException
-