aspose file tools*
The moose likes JSP and the fly likes Exception when I try to iterate through a loop in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

Exception when I try to iterate through a loop in JSP

dekij ra
Ranch Hand

Joined: May 21, 2010
Posts: 37
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

Joined: Oct 29, 2006
Posts: 124
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?


Do you know why this cup is useful? Because it is empty.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 21, 2010
Posts: 37
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 21, 2010
Posts: 37
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

Joined: Sep 29, 2008
Posts: 12617

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception when I try to iterate through a loop in JSP