wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to detect if a request value contains a String or a Stringarray Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to detect if a request value contains a String or a Stringarray" Watch "How to detect if a request value contains a String or a Stringarray" New topic
Author

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

Mark Mescher
Ranch Hand

Joined: Oct 25, 2004
Posts: 34
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

Joined: Jan 10, 2002
Posts: 60055
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Jan 24, 2005
Posts: 489


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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Sep 09, 2004
Posts: 49
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to detect if a request value contains a String or a Stringarray
 
Similar Threads
Generated Holder Types
basic syntax question ?
java.lang.string
string array question
how to cast array of Object