Example usage for javax.servlet RequestDispatcher FORWARD_CONTEXT_PATH

List of usage examples for javax.servlet RequestDispatcher FORWARD_CONTEXT_PATH

Introduction

In this page you can find the example usage for javax.servlet RequestDispatcher FORWARD_CONTEXT_PATH.

Prototype

String FORWARD_CONTEXT_PATH

To view the source code for javax.servlet RequestDispatcher FORWARD_CONTEXT_PATH.

Click Source Link

Document

The name of the request attribute under which the original context path is made available to the target of a #forward(ServletRequest,ServletResponse) forward

Usage

From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java

private void doForward(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation)
        throws ServletException, IOException {

    // Reset any output that has been buffered, but keep headers/cookies
    response.resetBuffer(); // Servlet-3_1-PFD 9.4

    //Wrap the request
    ForwardRequest wrequest = new ForwardRequest(request, response, invocation);

    // If we have already been forwarded previously, then keep using the established
    // original value. Otherwise, this is the first forward and we need to establish the values.
    // Note: the established value on the original request for pathInfo and
    // for queryString is allowed to be null, but cannot be null for the other values.
    if (request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) == null) {
        // ??,//from  w  w w  .  j a v  a2s  .com
        wrequest.setAttribute(RequestDispatcher.FORWARD_REQUEST_URI, request.getRequestURI());

        wrequest.setAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH, request.getContextPath());
        wrequest.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, request.getServletPath());
        wrequest.setAttribute(RequestDispatcher.FORWARD_PATH_INFO, request.getPathInfo());
        wrequest.setAttribute(RequestDispatcher.FORWARD_QUERY_STRING, request.getQueryString());
    }

    boolean isValid = false;

    try {

        invocation.getFilterChainInvocation().service(wrequest, response);

        isValid = true;
    } finally {
        if (request.getAsyncContext() != null) {
            // An async request was started during the forward, don't close the
            // response as it may be written to during the async handling
            return;
        }

        // server/106r, ioc/0310
        if (isValid) {
            finishResponse(response);
        }
    }
}