GeeCON Prague 2014*
The moose likes Servlets and the fly likes Processing Identically Named Form Fields? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Processing Identically Named Form Fields?" Watch "Processing Identically Named Form Fields?" New topic
Author

Processing Identically Named Form Fields?

Jason Ferguson
Ranch Hand

Joined: Sep 16, 2007
Posts: 47
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

Joined: Jan 10, 2002
Posts: 61314
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jason Ferguson
Ranch Hand

Joined: Sep 16, 2007
Posts: 47
Thanks Bear (yet again). Now that you point out getParameterValues(), it seems like I asked a dumb question.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

If you learned something you didn't know, how is it dumb?
[ January 20, 2008: Message edited by: Bear Bibeault ]
 
GeeCON Prague 2014
 
subject: Processing Identically Named Form Fields?