my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes problem in getInitParameterNames() method of ServletConfig Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "problem in getInitParameterNames() method of ServletConfig " Watch "problem in getInitParameterNames() method of ServletConfig " New topic
Author

problem in getInitParameterNames() method of ServletConfig

Joshua Antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 254
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


SCJP,SCWCD, Into ATG now!
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
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.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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 ?


[My Blog]
All roads lead to JavaRanch
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Wow, three simultaneous posts
Joshua Antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 254
Thanks all for your replies.
I got the point.

Kind Regards,
Joshua
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in getInitParameterNames() method of ServletConfig
 
Similar Threads
TomCat refuse to execute init(), but WebLogic could!
Struts 1.3.5 -- Module 'null' not found. Null Pointer Exception
web.xml, java.io.ByteArrayInputStream
Need for the contextConfigLocation
How to avoid directory listing?