Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem iterating over implicit EL header object

 
Ste Graham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On my workstation which is running Tomcat 5.5 (Java 1.5 JVM) the following code works and prints out the HTTP headers:



However, when I copy it over to our server which is running Tomcat 6 (1.6 JVM) I get the following output:



Why is this? Any help/advice much appreciated!

Stephen
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either Tomcat changed the toString() method on their implementation class, or they changed the class itself.

I haven't tried it myself, but you should be able to retrieve the key and value properties of the entry (rather than relying upon the toString() of the entry itself).
 
Ste Graham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I have now:



, and this works. For some reason I didn't know you could reference the names and values like this! ops:

Stephen
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL leans on getters/setters. ${foo.bar.waa} roughly translates to "foo.getBar().getWaa()".

java.util.Map.Entry has getKey() and getValue() methods.

[Edit: not-so-nice portion removed]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What may not have been obvious is that the iteration elements implement Map.Entry.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${header} refers to a java.util.Map.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic