On Tue, 4 Jun 2002, Jay Burgess wrote:
> > -----Original Message-----
> > From: David Mossakowski [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, June 03, 2002 10:23 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: req.getParameterMap()?!?
> >
> >
> > How about enumerating through a request.getParameterNames and getting
> > values by calling request.getParameter?
> >
> > come to think of it why are you first calling a _dismantling_
> > method and
> > then manually putting the query together?
> >
> > how about calling request.getQueryString?
> >
> Because it's a POST request, and getQueryString() doesn't return name/value
> pairs from the POST body. getParameterNames() appears to consolidate both
> actual query string pairs with any more found in the body. It seemed like
> the easy way to go, but I've never seen a method return something where you
> had to check the instanceof to know how to operate on it.
Well, you still shouldn't need to. I thought there was some specific
reason you're using getParameterMap (and it looks like that's why you
end up needing/using instanceof in the code below; I'm not real
familiar with HashMap's and Iterator's). But if you can just use
getParameterNames, you can then use getParameterValues to get a String
array of all the parameter values for a given parameter name -- no
need to do an instanceof.
BTW, getParameter will return the value in the first element of the
array returned by getParameterValues. This is all in the spec -- as
is that parameters from the query string and the POST body are
consolidated. If you want just the parameters in the POST body, I
think you have to read/parse the body yourself (it's something like
that the first call to a getParameter*-related method parses
everything, the query string and the POST body -- if any -- so if you
don't call any of those methods, the body should be intact for you to
parse; again, this is probably all in the spec).
> > Jay Burgess wrote:
> > > I want to build a String version of my request parameters
> > based on the
> > > HashMap returned by getParameterMap(). I'm amazed that I
> > have to do the
> > > "instanceof" check below. Can someone confirm that this is the
> > > requirement? (It doesn't work otherwise, and it's not
> > clear to me why
> > > getValue() doesn't just always return an array.)
> > >
> > > Iterator iter = req.getParameterMap().entrySet().iterator();
> > > while (iter.hasNext()) {
> > > Map.Entry entry = (Map.Entry) iter.next();
> > > String key = (String) entry.getKey();
> > > Object obj = entry.getValue();
> > > if (obj instanceof String) {
> > >
> > params.append("&").append(key).append("=").append((String)
> > > obj);
> > > }
> > > else { // else it must be an Array
> > > String [] values = (String []) obj;
> > > for (int i = 0; i < values.length; i++) {
> > > String value = values[i];
> > >
> > > params.append("&").append(key).append("=").append(value);
> > > }
> > > }
> > > }
> > >
> > > Thanks.
> > >
> > > Jay
> > >
>
> ___________________________________________________________________________
> 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
>
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