Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Syntax Confusion  RSS feed

 
bob reilly
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My experience with JSP and Java for that matter is somewhat limited. I've been surfing the Internet looking for an explanation with some of the syntax below. If someone can provide some insights thanks -

List l =fvm.vendors(fvm.getCon());

Iterator it =l.iterator();
Vendor v = new Vendor();
while(it.hasNext()){
v = (Vendor) it.next();
}
request.setAttribute("name",v.getVendor_name());

The syntax that has me confused: "V = (Vendor) it.next()". I believe the it.next content is being converted to "Vendor" object. Is this correct?

If you could elaborate on this it would help.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the next() method returns the next object in the list (like popping something off of a stack). You're then casting that object down to a Vendor object.

Note: in your code, you're looping through the list but only using the last copy of v that was returned.
[ February 04, 2008: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear, what you are dealing with here is good old straight-forward Java syntax. It really has nothing to do with JSP (except that, I assume, it's embedded in a JSP).
 
bob reilly
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent - thanks guys!!
 
kelby zorgdrager
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not to be overly pedantic.. but, you aren't converting the object nor are you down casting the object..

the object in the List already is a Vendor... its the reference to the object that you are casting..
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!