Merging request parameters when doing forward

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Merging request parameters when doing forward

Roman Puchkovskiy-2
Hi.

When a forward is made using RequestDispatcher.forward(), Jetty merges parameters in existing request with parameters of forward (i.e. those that are specified in a query string of path used to obtain a RequestDispatcher).

If the same parameter is both in existing request and in forward path, both parameter instances remain in the query string after the forward.
Let's assume we have two servlets, one of them is SourceServlet, bound to /source context, another is TargetServlet, bound to /target context.

doGet() method of the TargetServlet is

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        writer.println(req.getQueryString());
        writer.flush();
        writer.close();
    }

So it just dumps the query string.
doGet() method of the SourceServlet is

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.getSession().getServletContext().getRequestDispatcher("/target?name=forwardValue")
                .forward(req, resp);
    }

It forwards to TargetServlet using a query string 'name=forwardValue'.
After deploying webapp with these two servlets to Jetty and going to the following path:
/source?name=initialValue
we see the following in the output:
name=forwardValue&name=initialValue

So, both values are in the resulting query string after the forward.

But the Servlet specification says:
"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."
(servlet-2_4-fr-spec.pdf, page 64, section 'SRV.8.1.1 Query Strings in Request Dispatcher Paths')
So it seems that when parameter with the same name is encountered in initial request and in forward path, the latter should take precedence and the former should be eliminated.

When repeating steps described here in Tomcat, I see the following output:
name=forwardValue

I.e. in Tomcat parameter from forward path takes precedence.

What do you think about all this? Could this be a bug in Jetty?

Thanks in advance.