Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple for loop problem

Status
Not open for further replies.

mrDrive

MIS
Aug 29, 2002
94
0
0
US
Hi,

I'm very new to JSP. When I use a for loop to iterate through an array, it always prints "null" at the end of the loop.

Here's how I'm using it:

Code:
String[] myArray = request.getParameterValues("selectElement");
int i;
for (i=0; i < myArray.length; i++) {
out.println("myArray[" + i + "]</strong> = " + myArray[i] + "<br>");
}

Thanks for any help!
 
i presume the array is storing the values of checked checkboxes. it could be the value of the last checkbox thats passing null.
 
No, it's actually (in this case) a select element with the multiple attribute added. So when I use "request.getParameterValues" it treats it as an array.

I've got the same problem when I use a for loop on an different array:

Code:
String CommaDeleneatedString = RecordSet.getString("DatabaseField");
String[] myArray = CommaDeleneatedString.split(",");
for (i=0; i < myArray.length; i++) {
   out.println("myArray[" + i + "]</strong> = " + myArray[i] + "<br>");
}
 
Hi,

I think the String CommaDeleneatedString might have null at the end.
ex:String CommaDeleneatedString = "one,two,three,four,null";

Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top