Adding = to a parameter does cause it to be available to the destination
servlet, but that doesn't seem like a particularly good solution.  A
parameter without a value is technically a keyless value, not the other way
around.  But I'll stick to the servlet terminology of calling them
parameter names and values since request.getParameterNames and
getParameterMap both return them as "Names" and not a value without a
name.  Parameters without a value (keyless value) are widely used and
within spec without having to add the =.

I wrote a couple of servlets and have been able to narrow down the problem
to take form POST data out of the equation, but not been able to find a
solution yet.  I'm even more convinced that
getRequestDispatcher().forward() or the receiving servlet are borking the
parameters.

This works:
Directly access /page1?a=1&b&c=3&d
The request arrives at the servlet with all 4 parameters, a and c have
values, b and d don't but are in the parameter names list.

This doesn't work:
request.getRequestDispatcher("/page1?a=1&b&c=3&d").forward(request,
response);
The request arrives at the servlet with only the parameters a and c, not b
and d.  All 4 parameters are in the query string, but b and d are not in
the parameter names list or map.

Seems to me that if the exact same servlet can accept parameters without a
value on a direct request, but fails on only some parameters when it's from
a request dispatcher that something is wrong where the parameters are
gathered the second time, or somewhere before they are made available to
the destination.

On Mon, Jan 11, 2016 at 3:41 PM, Andreas Junius <andr...@junius.info> wrote:

> Did you try:
>
> "/page2?foo=&bar=123"
>
> Normally parameters come as key/value pairs, separated by an equal sign.
>
>
>
> On 12/01/16 09:21, Mark Olsson wrote:
>
>> I'm getting unexpected parameter handling with a
>> request.getRequestDispatcher().forward().  Not sure if this is a bug or
>> I'm
>> using gRD.f wrong, but here's the situation:
>>
>> A POST is made with form data to a servlet (didn't try with a multipart
>> content, just regular) and the servlet decides to redirect to another
>> servlet using request.getRequestDispatcher().forward(), but adds
>> parameters
>> on the new address.  Address parameters with a value "asdf=123" *are* sent
>> to the new servlet but parameters without a value *aren't*.
>>
>> Example:
>> 1. POST made to page1 with parameters input1="asdf" and button1 (no
>> value).
>> 2. The servlet handling page1 redirects to page2 and adds 2 parameters:
>>
>> request.getRequestDispatcher("/page2?foo&bar=123").forward(request,response).
>> 3. page2 gets the original parameters input1="asdf", button1, and new
>> bar="123" but not foo.  foo is in the browser address and is in the
>> request
>> query string, but it's not one of the parameters sent along with the
>> request object.  Neither request.getParameterNames() nor
>> request.getParameter() will find "foo".  It also doesn't appear in the
>> list
>> of parameters in Netbeans' server monitor.
>> 4. Changing the order of the parameters (/page2?bar=123&foo) doesn't fix
>> it, but adding a value to foo does (/page2?foo=x&bar=123).
>>
>> So what's up with valueless parameters on a servlet forward?
>>
>> Tomcat: 8.0.26
>> Java: 1.8.0_60 Oracle
>> OS: Win7 and Linux 3.14.20-20.44.amzn1.x86_64
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to