Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mark Mescher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic