• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

deviation in the return type of getParameterValues() method

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why did the authors have a String array as the return type for the getParameterValues() method of ServletRequest interface but for all the other methods which return multiple values such as getHeaderNames() of HttpServletRequest interface, getAttributeNames() method of ServletContext interface, getInitParameterNames() method of ServletConfig interface etc., have java.util.Enumeration as the return type ?
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that getParameterValues() returns only values, not the pairs like in the other methods.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that getParameterValues() returns only values, not the pairs like in the other methods.
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What pair ???
All of them return return 0 or more values.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,

Welcome back to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We request that display names be of the pattern FIRST_NAME+SPACE+LAST_NAME.

Thanks Pardner! Hope to see you 'round the Ranch!
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pairs [key;value] so they are stored in some kind of collection, and maybe they are returned via Hashtable.elements . And you can see there is a method getParameterNames() which return Enumeration and the method getParameterValues(String name) which return an array of String. Parameter names are unique and could be iterated but one parameter could have more than one value. [key;value[]]
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,
Following is the output of request.getHeaderNames() on my meachine

accept
accept-language
accept-encoding
user-agent
host
connection
cookie

it returns only names (value) of header elements,i.e all these method returns 0 or move value and not [key;value] to get value of this name we have a method call getHeader(String name).

This can be achived by returning 1D String array,instead of Enumeration,so question is why the difference in return type?

cheers
Praful
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Header names are something constant :-). But parameters passed to the servlet may vary. Sometimes could one parameter take more values (array)
and the function must return this array.
It could look like this.

 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,
I agree to your statement,Header names are something constant :-). But parameters passed to the servlet may vary. Sometimes could one parameter take more values (array)

But same thing is achivable by returning enumeration from method getParameterValues, as follows.
If I have to develop such methods then I would preffer to keep the return type of all methods same either by applying this logic to getParameterValues
or your logic to methods like getHeaderNames,getParameterNames etc.

(anyone kinldy correct me if I'm going wrong)

So the question still remains,why Sun choose to have different Return type for getParameterValues







Cheers
-P

[ August 26, 2004: Message edited by: Praful Thakare ]
[ August 26, 2004: Message edited by: Praful Thakare ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? - How about because it is simpler and faster! Particularly in the very common case of only a single value associated with a parameter name.

I'll never understand why people start arguments like this.
Bill
 
John Mallavalli
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have asked this question since I haven't found any other method of similar kind returning String array. And if the reason is being simpler, why didnt the authors use it for other similar methods instead of using Enumeration.

For example, the getHeaders(String name) method of the HttpServletRequest is somewhat similar to the getParameterValues(String name) method. So why didnt the authors use String[] as the return type for the getHeaders() method if it was simple.

I had not asked this question for argument sake but I really would like to know the reason behind making that decision.
Sorry if I sound crazy(sometimes I do though!!)

Thanks,
John
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? - How about because it is simpler and faster! Particularly in the very common case of only a single value associated with a parameter name

In that case,getHeaderNames(),getHeaderNames(),getInitParameterNames() must return String array,as They come under comman case of Only a single value associated with parameterand they return values which can be embraced by 1D String array.

I'll never understand why people start arguments like this.


May be cause people are trying to find the answer of somthing which they find either strange,or weard,or they think there is some reason which is out of there thinking reach

Cheers
-P
[ August 26, 2004: Message edited by: Praful Thakare ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look up the source code for the implementation of HttpRequest in Tomcat.
org.apache.catalina.core.ApplicationHttpRequest.java
You will see there that the request parameters have been parsed by the servlet engine into a HashMap having the parameter names as keys and String[] as the stored value.
Therefore the String[] can be returned with no further manipulation in the getParameterValues( String name ) method.
Thats one of the great things about using Tomcat - you can get the source.
Bill
 
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic