public interface RequestDispatcher
RequestDispatcher disp;
disp = request.getRequestDispatcher("inc.jsp?a=b");
disp.include(request, response);
Servlets typically use ServletRequest.setAttribute()
to communicate between included pages.
A popular architecture uses servlets to process the initial request
and JSP files to format the results. That template architecture uses
request attributes to communicate data from the servlet to the JSP page.
disp.forward()
transfers the request to the JSP file.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ERROR_EXCEPTION |
static java.lang.String |
ERROR_EXCEPTION_TYPE |
static java.lang.String |
ERROR_MESSAGE |
static java.lang.String |
ERROR_REQUEST_URI |
static java.lang.String |
ERROR_SERVLET_NAME |
static java.lang.String |
ERROR_STATUS_CODE |
static java.lang.String |
FORWARD_CONTEXT_PATH |
static java.lang.String |
FORWARD_PATH_INFO |
static java.lang.String |
FORWARD_QUERY_STRING |
static java.lang.String |
FORWARD_REQUEST_URI |
static java.lang.String |
FORWARD_SERVLET_PATH |
static java.lang.String |
INCLUDE_CONTEXT_PATH |
static java.lang.String |
INCLUDE_PATH_INFO |
static java.lang.String |
INCLUDE_QUERY_STRING |
static java.lang.String |
INCLUDE_REQUEST_URI |
static java.lang.String |
INCLUDE_SERVLET_PATH |
Modifier and Type | Method and Description |
---|---|
void |
forward(ServletRequest request,
ServletResponse response)
Forwards the request to another page.
|
void |
include(ServletRequest request,
ServletResponse response)
Includes the result of another page.
|
static final java.lang.String ERROR_MESSAGE
static final java.lang.String ERROR_EXCEPTION
static final java.lang.String ERROR_EXCEPTION_TYPE
static final java.lang.String ERROR_REQUEST_URI
static final java.lang.String ERROR_SERVLET_NAME
static final java.lang.String ERROR_STATUS_CODE
static final java.lang.String FORWARD_CONTEXT_PATH
static final java.lang.String FORWARD_PATH_INFO
static final java.lang.String FORWARD_QUERY_STRING
static final java.lang.String FORWARD_REQUEST_URI
static final java.lang.String FORWARD_SERVLET_PATH
static final java.lang.String INCLUDE_CONTEXT_PATH
static final java.lang.String INCLUDE_PATH_INFO
static final java.lang.String INCLUDE_QUERY_STRING
static final java.lang.String INCLUDE_REQUEST_URI
static final java.lang.String INCLUDE_SERVLET_PATH
void forward(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
response.reset()
method to clear
the output buffer.
Query parameters are added to the original query parameters.
The new URI values are based on the RequestDispatcher URI. So getRequestURI(), getServletPath(), and getPathInfo() will reflect the request dispatcher URI.
request
- the original requestresponse
- the original responseServletException
java.io.IOException
void include(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
Query parameters are added to the original query parameters.
The included request's URI methods reflect the original URI data. So getRequestURI() will return the URI sent by the browser.
Included pages should use request.getAttribute() to get the new URI values:
getRequestURI | javax.servlet.include.request_uri |
getContextPath | javax.servlet.include.context_path |
getServletPath | javax.servlet.include.servlet_path |
getPathInfo | javax.servlet.include.path_info |
getQueryString | javax.servlet.include.query_string |
request
- the original requestresponse
- the original responseServletException
java.io.IOException