On Tue, 4 Jun 2002, Jay Burgess wrote: > I'll try this again, but I'm 99% sure if I only have one parameter > value, trying to cast it to an array fails (as it's simply a > String). But maybe I screwed up my testing yesterday, so I'll give > it another spin this morning. > > And maybe I'll punt getParameterMap() altogether, and look at using > getParameterNames(), etc. to do the same thing.
Once again, getParameterValues is your friend. It returns a String array, all the values for a given parameter name. and the first element of the array is what getParameter would return. So if you're always sure you'll have at most one value, use getParameter. If you're not, use getParameterValues. (BTW, the javadocs for the servlet API indicates getParameterValues will return NULL, not an empty array, if the parameter doesn't exist.) > > -----Original Message----- > > From: Gennis Emerson [mailto:[EMAIL PROTECTED]] > > Sent: Monday, June 03, 2002 9:59 PM > > To: [EMAIL PROTECTED] > > Subject: Re: req.getParameterMap()?!? > > > > > > Jay Burgess wrote: > > > > > > [question re ServletRequest.getParameterMap values: > > String[] or > String] > > > > From the 2.3 spec: > > > > SRV.14.2.16 ServletRequest > > > > getParameterMap() > > > > public java.util.Map getParameterMap() > > Returns a java.util.Map of the parameters of this request. Request > > parameters are extra information sent with the request. For HTTP > > servlets, parameters are contained in the query string or posted form > > data. > > > > Returns: an immutable java.util.Map containing parameter names as keys > > and parameter values as map values. The keys in the parameter > > map are of > > type String. The values in the parameter map are of type String array. > > > Milt Epstein Research Programmer Systems and Technology Services (STS) Campus Information Technologies and Educational Services (CITES) University of Illinois at Urbana-Champaign (UIUC) [EMAIL PROTECTED] ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
