Mantis - Resin
Viewing Issue Advanced Details
4431 minor always 03-09-11 20:10 04-06-11 16:41
mhixson  
ferg  
normal  
closed 4.0.15  
fixed  
none    
none 4.0.17  
0004431: Including a query string in resin:Forward's target results in duplicated request parameters
Say I include the following in my web.xml:

    <resin:Forward regexp="^/foo$" target="/bar?a=1" />

And I define the following servlet:

    @WebServlet(urlPatterns="/bar")
    public class BarServlet extends HttpServlet
    {
      @Override
      protected void doGet(HttpServletRequest request,
                           HttpServletResponse response)
          throws ServletException, IOException
      {
        response.getWriter().write(
            Arrays.toString(
                request.getParameterValues("a")));
      }
    }

Then I make a request to this URL:

    /foo?a=2

I see an output of "[2, 1, 2]" rather than the expected "[1, 2]". It seems that any parameters I define in the request are put into the parameter map twice.
I notice that in my BarServlet example, the following is true:

    request.getQueryString(); // Returns "a=1&a=2".
    
    request.getAttribute(
        RequestDispatcher.FORWARD_QUERY_STRING); // Returns "a=2".
    
    request.getParameterValues("a"); // Appears to be a combination of the
                                     // two query strings.

That request.getQueryString() is the combination of the one in my resin:Forward rule and in the actual request is different from the behavior of a raw RequestDispatcher.forward call. In that case, request.getQueryString() would be simply "a=1".

I have worked around this in my application by extending the com.caucho.rewrite.Forward class, and overriding the rewriteTarget method like so:

    @Override
    protected String rewriteTarget(Matcher matcher,
                                   String uri,
                                   String queryString)
    {
      return super.rewriteTarget(matcher, uri, null);
    }

However, I'm guessing that's not the proper solution.

Notes
(0005173)
ferg   
04-06-11 16:41   
server/1knb