Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

Exception when I try to iterate through a loop in JSP

 
dekij ra
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, I receive a NumberFormatException when I try to iterate through a loop in a JSP. below is my code



And this is my JSP

 
Hongli Li
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Report post to moderator
what's the signature of getPeopleByLastName in SearchVolunteer, it looks like the it's expecting an number but got an string which can't be converted to a number.
and did your code compile at all?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65221
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
What you've shown us will not cause a NumberFormatException. What else is going on in the JSP?

Not that this has anything to do with the problem, but why are you setting the scoped variable in a loop? That's just going to keep overriding the same variable over and over again.

Also, please format your code a little better. It's very hard to read; and be sure to apply the proper use of {}; for your for-loop, for example.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Just for clarification:This code will loop over the list of people, check to see if the list itself is empty, and repeatedly set the same request attribute to the list. It might be more efficient to do this:Or, if *I* were doing it, simply:
 
dekij ra
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Report post to moderator
Ok, here is more of my code

This is the servlet that calls a SearchPerson(String last_name) function, and gets a value for last name from the JSP page I have posted below this servlet code.


This is the JSP page which the servlet gets the value of last_name in the text box and returns the people list


This is the Person class constructor



 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
There's no looping in JSP here as you stated in your first post, and I still don't see anything related to a NumberFormatException.
 
dekij ra
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, thanks for the reply. Well, I was trying to loop inside the servlet and then have that display in the cut. And that is what I was trying to do with the loop in my first post...however it didn't work out. Basically if I do the following below I get a successful execution and the query displays properly.



However, if I have two same last names in the database (i.e. Smith) then only one of them displays! I want all of them to display, hence why I am trying to loop through the list somehow, either in JSP or servlet
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Just put the entire list into the request; I don't see what the issue is. I still don't see any JSP looping or anything that would cause a NumberFormatException.

Perhaps you should start over and PostRealCode?
 
    Bookmark Topic Watch Topic
  • New Topic