Link to home
Start Free TrialLog in
Avatar of boyyle
boyyle

asked on

request.getParameterValues()---how?

i have this code in my jsp page:

<%
String myArray[] = request.getParameterValues("myTextBox");
int myLength = java.lang.reflect.Array.getLength(myArray);
%>

so,my concern is, if myArray[] not empty,the java.lang.reflect.Array.getLength is working.
but if myArray[] is empty, i get the error message....
so, may i know is there any function to check whether the myArray[] is empty or not???

thanx
Avatar of yongsing
yongsing

Check if it is null.
To check the length of array, you can use
    myArray.length

This will return 0 if the myArray empty.int myLength = (myArray == null ? 0 : myArray.length);
myArray.length
ASKER CERTIFIED SOLUTION
Avatar of quangnt
quangnt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Barry
I believe Array.length(array) returns the same thing as array.length.
SO I'd say the problem is that you need to check if null as yongsing originally stated.