Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection and Iterator

 
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: 65653
129
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: 65653
129
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!