• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection and Iterator  RSS feed

 
Adam Teg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following in my jsp
Collection allSubjects = (Collection) session.getAttribute("allSubjects");
Iterator subjectIterator = (Iterator) session.getAttribute("subjectIterator");

for (Iterator it=subjectIterator; it.hasNext(); )
{
subject = (Subject) it.next();
***subject.getSubjectName();***
}

The subject.getSubjectName() does not return anything ALTHOUGH in the SERVLET before dispatcher the collection has elements. All imports are done correctly. Let me know if you have any ideas.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66264
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing an iterator to a JSP is rather bizarre. Is it an iterator for allSubjects? If so, why pass it separately?
 
Adam Teg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is. If it is bizzare that is because I don't know any better.
 
Adam Teg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the "bizarre". I declared a new iterator and it works.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66264
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iterators are finicky things to be passing around, as you discovered. It's best to keep them localized.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!