This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi, due to confusion on my previous thread, I'm starting a new one. So, I have a function called getPeopleByLastName(String last_name) and I'm calling it in a servlet (below). It is supposed to retrieve the value from DB and put it into the <c: out> tag for firstName. However I receive the following exception
This is my JSP - which is supposed to retrieve input from the people.lastName and display the name retrieved from the DB in people.firstName (all processed by the servlet which calls the getPeopleByLastName function in another class
This is my servlet
And here is my constructor for Person class...not sure if it helps or not
This might help as well...it's the code for the search function - the select statement is not shown..but there's nothing wrong with it
I'd appreciate any help
dekij ra
Ranch Hand
Joined: May 21, 2010
Posts: 37
posted
0
One thing I'd like to note is that if I have the following code below - everything works...however, it only works for the first person in the database with the last name entered in the search criteria. If there is a second person with the same name, it will not get displayed. And I want all of the people with the same to be displayed, not just the first one that the program encounters....and for that I am thinking I need some sort of a loop...?
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
posted
0
I don't think the problem is in the code you posted.
From the message i see, you are trying to handle the String "last_name" as if it was a number. Are you trying to convert to number some String? if yes, probably there the exception is thrown.
In the future, please continue in the original thread. I have closed that one as you have started this one. But please, next time, just keep things to one topic.
I still don't see anything that can cause a conversion error, but it's senseless to focus on that when the posted code is so clearly broken.
You are setting a list as a scoped variable, and then treating it like a bean on the JSP page. That obviously won't work. If you want to show the entries in the list, you need to iterate over the list with <c:forEach>
dekij ra
Ranch Hand
Joined: May 21, 2010
Posts: 37
posted
0
Hello, I really appreciate all of the help with this issue...To answer the questions, no I am not doing any number conversions to String anywhere. The field is also set to varchar in the DB. So, considering that, I think it has to do with the number of entry in the list?
So, considering that the following code is ok, I've tried to do a loop inside the JSP page
And here is a loop in my JSP, trying to iterate through the Person list
How about instead of posting fragments of the JSP you post the entire thing? Because "lastName" isn't remotely involved in the JSP fragment you say causes the error:By the way, "personlist" is a crappy name for something holding a single person.
You're saying if you take this code out of the JSP you no longer get the exception?
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
posted
0
Ok,then you could post the jsp, there's a subtle mistake, so evident that you can't even imagine to see it.
dekij ra
Ranch Hand
Joined: May 21, 2010
Posts: 37
posted
0
Ok, below is my whole JSP page. I appreciate all of your help. This problem has been drivivng me insane for the past week. I've spent so many hours on it. Could it be a problem with the conversion of firstName to a list index??
What have you done to try and isolate the problem? Comment out the elements in the JSP and start adding them back a bit at a time. That can help isolate the specific element that's triggering the issue.
dekij ra
Ranch Hand
Joined: May 21, 2010
Posts: 37
posted
0
Well, as I said before, if I replace the following code
With this
it works fine, however it only gets the first person with the specified last name from the database. if there is another person with the same last name, it does not display him.
in the JSP i simply have this
So far, this leads me to believe that there is something wrong with the index of the Person list and I am doing something wrong in assigning it using a <c:ForEach> loop...All that I'm trying to do is receive text input from the JSP, insert that input in the search function inside the servlet and return the value of first name in a person list somehow...
If people isn't a single person, then ${person.lastName} is trying to apply the "lastName" part to a list--that obviously won't work. You need to either send a list, or send a single person, and make sure the JSP code matches with the Java.
In the code fragmentyou're attempting to treat the same variable ("people") as both a single person and as a list.
"personlist" is still a silly name for something that's actually a single person. How about... "person".
Glad you got it worked out. It's not so much about removing that line, it's about keeping track of what you're passing around. You can still pass the value, just not in the way you were trying to do it. (And it's important to include the necessary information when asking questions, particularly when multiple people point out that the code you posted couldn't possibly cause the error! :)
dekij ra
Ranch Hand
Joined: May 21, 2010
Posts: 37
posted
0
Yes, I really appreciate the help. Thanks once again.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.