• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in getInitParameterNames() method of ServletConfig

 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A part of my deployment descriptor is as below.





Although 2 parameters are mentioned here but during the execution of the following code:





I get output as name2 name1 .
Why is line seperator not taking any effect. And why is the order in the output different I mean name2 and then name1 and not the other way round.

Kind Regards,
Joshua
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by joshua antony:

I get output as name2 name1 .
Why is line seperator not taking any effect.


Do "view source" on the browser page. You should see two lines. In HTML \n is just a space. To display a new line, use <br>.


Originally posted by joshua antony:

And why is the order in the output different I mean name2 and then name1 and not the other way round.


Enumeration returns elements in the order supplied to it by the underlying Collection. The servlet specification makes no statements about that Collection. It does return the elements is some order, just not in the order you expected.

My guess is that it uses some HashMap to store paramname - paramvalue pairs and returns a Set (probably a HashSet) of parameter names using map.keySet(), which in turn is the underlying collection for the Enumeration. If you really want to know the algorithm which is used by HashSet for returning elements, you have to look at HashSet source because the API doesn't specify (and thus, guarantee) it.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is line seperator not taking any effect.

Are you outputting into the web browser ? If so, maybe you should try the "br" tag instead.

And why is the order in the output different I mean name2 and then name1 and not the other way round.

It's not specified anywhere that the order of the initparams will be the same.
Who cares about the order anyway ?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right click and select View Source in your browser to see the lines separated. The browser simply treats the break as a single space when it renders content to the screen.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, three simultaneous posts
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your replies.
I got the point.

Kind Regards,
Joshua
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic