• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Processing Identically Named Form Fields?

 
Jason Ferguson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't try this for myself for a few days, but would like to try to find out so that I don't waste my time when I can do it.

Supposing I had a JSP with two identical text input fields:

<form action="/processingServlet">
<input type="text" name="serialNumber" />
<input type="text" name="serialNumber" />
<input type="submit" value="Add Serial Numbers" />
</form>

When the form is submitted to the ProcessingServlet, what would be in the HttpServletRequest for serialNumber? An array, or nothing?

Again, I'd try for myself, but it will be a few days before I can.

Jason
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTTP request will have both name/value pairs. But you don't care about that unless you are parsing the request yourself.

To get both values as an array, be sure to use the getParameterValues() method.
[ January 20, 2008: Message edited by: Bear Bibeault ]
 
Jason Ferguson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear (yet again). Now that you point out getParameterValues(), it seems like I asked a dumb question.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you learned something you didn't know, how is it dumb?
[ January 20, 2008: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic