• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to detect if a request value contains a String or a Stringarray

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi out there,
I have a little problem. I have a HttpServletRequest and I dont know if there is a Stringarray or a String behind a specific name. So I dont know if I have to use getParameter or getParameterValues to get the correct values.
Is there a possibility to check this before one of the two methods?
Thanx
Bye
Mark
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there is a possibility that more than one value can be returned, use getParameterValues. If there is only one value, you will get an array of one entry.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actuality is,

If we have a unique name for each parameter then we used to use getParameter(). And if more than one parameter with the same name then use getParameterValues().

Bear's suggestion will work anyway.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If we have a unique name for each parameter then we used to use getParameter(). And if more than one parameter with the same name then use getParameterValues().



well, sometimes it may be required to use getParameterValues() even when parameter names are unique (eg incase of select fields with the multiple select option turned on).

ram.

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramprasad madathil:
well, sometimes it may be required to use getParameterValues() even when parameter names are unique (eg incase of select fields with the multiple select option turned on).



Although, Its same like more than one parameter under same name.
But yeah, Missed that.

Thanks Ramprasad.
[ February 28, 2005: Message edited by: Adeel Ansari ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used getParameterValues() once when I don't actaully know the full name of the parameters. This is because the form was built dynamically based on user's action
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chit Ming Chong:
I used getParameterValues() once when I don't actaully know the full name of the parameters. This is because the form was built dynamically based on user's action




In that case you would want to use getParameterNames.

getParameterValues requires the name of the parameter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic