When in doubt, always go to the specification. In this case, see chapter 9.1.1 Query Strings in Request Dispatcher Paths
The
ServletContext
andServletRequest
methods that createRequestDispatcher
objects using path information allow the optional attachment of query string information to the path. For example, a Developer may obtain aRequestDispatcher
by using the following code:String path = "/raisins.jsp?orderno=5"; RequestDispatcher rd = context.getRequestDispatcher(path); rd.include(request, response);
Parameters specified in the query string used to create the
RequestDispatcher
take precedence over other parameters of the same name passed to the included servlet. The parameters associated with aRequestDispatcher
are scoped to apply only for the duration of the include or forward call.
So you can very well do
RequestDispatcher rd = getServletContext().getRequestDispatcher("/report?p="+value);
rd.forward(request, response);
And the parameter p
will be available only for HttpServletRequest
that is given to the resource mapped to handle the specified path, ie. /report
in this case. If that is a HttpServlet
, you can then access it with
request.getParameter("p");
where request
would be the HttpServletRequest
method parameter.
When the forward(..)
call terminates and execution comes back to your PreProcessingServlet
, the parameter will no longer be available in the local HttpServletRequest
object.