aspose file tools*
The moose likes JSP and the fly likes Difference in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Difference in JSP" Watch "Difference in JSP" New topic
Author

Difference in JSP

Abhinav Sharma
Greenhorn

Joined: Aug 08, 2001
Posts: 25
Hello everyone,
I know this is a kind a very stupid question. Cuz a person who has already done database connectivityis asking this question. But these are some very easy questions due to which i am not able to learn jsp properply. Can anyone tell me what is the difference between :-
When i say
Integer p=new Integer(12);
and
int u[]={1,2,3,4,5,6,7}
Whenever i add the Integer in the vector it adds it without any difficulty. But when we add int u[] it gives me error messege "No match was found for method." I am using a vector where i am storing string and integer both. I can store string which has more than one values but i cannot store integer more than one values. For that i have to store one value at a time. My question is that how can i store a integer array in a vector so that i can call it in a vector. As my vector consist both a string and Integer. I can store string array when i write :-
String st[]={"Abhinav :-","Bharat :- ","Shalini:- ","Abhay:-","Deepak :-","Farhan :-","Hanish :-","Jacob :-"};
And then add it in a vector
c.add(st);
And later call it by
<%=v.elementAt(0);%>
0th element is my string array.
Can i call a integer array also like my string array.
Thanks in advance
abhinav
ted oniger
Greenhorn

Joined: Aug 05, 2001
Posts: 16
Hi Sharma,
Since array (even array of primitive) is a special type of object and is a subclass of Object, therefore you can put in a vector.
You shouldn't have a problem adding the array of int in your vector. I have tried adding two arrays of int in a vector and it was OK.

int[] a = {1,2,3};
int[] b = {1,2,3};

Vector v = new Vector();
v.addElement(a);
v.addElement(b);
The code above compiled with no problem.
Hope this helps
Ted



Abhinav Sharma
Greenhorn

Joined: Aug 08, 2001
Posts: 25
hi ted,
Thanks for reply. But my problem still not solved. Well you can add int[] in a vector. But the problem is how to display the values inside the int.
My code is like this :-
<%
Integer p=new Integer(25);
int[] u = {1,2,3,4,5,6,7,8};
String st[]={"ID1 :- ","ID2 :- ","ID3 :- ","ID4 :- ","ID5 :- ","ID6 :- ","ID7 :-","ID8 :-"};
String st1[]={"Abhinav :- ","Bharat :- ", "Shalini:- ", "Abhay:- ", "Deepak :- ", "Farhan :- ","Hanish :- ", "Jacob :- "};
%>

<% for(int i=0;i<st.length;i++){
Vector v=new Vector();
v.addElement(st[i]);
v.addElement(st1[i]);
v.addElement(p);
v.addElement(u[i]);
%>
<%=v.elementAt(0);%>
<%=v.elementAt(1);%>
<%=v.elementAt(2);%>
<%=v.elementsAt(3);%><br>
<%}%>
I have used the same method to display a string value. And it does not shows any error. But when i use the same method for the int to display the values. it gives me the foloowing error.
"Errors reported by compiler :/jsp/WEB-INF/jsp/jrun__vec_new2ejspc.java:80:1:80:18: Error: No match was found for method "addElement(int)".
".
I can add it in vector but i cannot display it and if i use this to add the values in vecotr "v.addElement(u);". And then if i display the values then it shows me some thing like this "[I@2f1ad8". I hope my problem is more clear to you. Thanks again for taking pains to answer me.
abhinav
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference in JSP