0

Using fields with the same name in a POST form allows to obtain request values right into a List<String> variable:

<input name="colors" value="white">
<input name="colors" value="black">

Is there a similar idiomatic mechanism to handle key / value pairs?

I tried different random syntaxes in the name attribute and none triggered the same magic as my previous example so I figured out I could always invent mine. However this:

<input name="colors[background]" value="white">
<input name="colors[foreground]" value="blacks">

... causes the field to be missing from javax.servlet.http.HttpServletRequest.getParameter():

// None work
request.getParameter("colors")
request.getParameter("colors[background]")

This suggests square brackets have a special meaning anyway, albeit not the one I expected.

How should I handle my Hash variables? I'm using Jdeveloper 11g, WebLogic 10.3 and Jersey 1.17 in case there's an implementation extension not mandated by JAX-RS.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • 2
    Does this answer your question? [sending List/Map as POST parameter jersey](https://stackoverflow.com/questions/8413608/sending-list-map-as-post-parameter-jersey) – David Webb Jun 10 '20 at 07:42
  • @DaveWebb In that question they use Jersey as client rather than having an HTML form so it's unclear what the `name` attribute should be. Also, form params are captured as method arguments rather than grabbing them from `HttpServletRequest`. I could rewrite my app that way but I'd like to know for sure whether it's necessary. – Álvaro González Jun 10 '20 at 08:26

0 Answers0