vectors from servlet
hi all, in my jsp application i am using applet in one of my jsp to display tree structure.when the users select the tree nodes and click on the set button,my respective servlet reads all the node values from the applet and store it in a vector.now i want those vector in my jsp page.
now to get those vectors in my jsp iam forwarding the request to another jsp and retrieving those vectors.in that jsp i am storing those vectors in a session but when i try to get those vectors in any other jsp page using session.getAttribute() its giving null. hope its creating a different session for my servlet whose work is to only reads the data from my applet.
so how to solve this problem.its a urgent task for me.any help will greatly b appreciated.
thanks in advance
[786 byte] By [
paridaa] at [2007-11-27 6:18:56]

# 1
hi,
it's impossible to store the vector in session.
becoz session only return the String not an object.
so u can try with the getter and setter method to solve this problem, for ex.
public void setData(Vector v) {
// some code here
}
public Vector getData() {
return Vectorobject;
}
Message was edited by:
art84
art84a at 2007-7-12 17:33:13 >

# 3
hi,
i think u have no pblm to adding values in vector.
after that pass the vector object to setter method.
see my below code.
in my servlet i cretae one vector and adding some values in that vector and write the getData(Vector v) in the same program.
Simple.java
/* code here */
{
Vector v = new Vector();
v.addelement(objectname);
}
public Vector getData() {
return v;
}
/* code here*/
u can retreive the vectopr value in another jsp/servlet using the getData() ;
i think this code ll help u lot.
Bala
art84a at 2007-7-12 17:33:13 >

# 4
@OP
>it's impossible to store the vector in session.
Very untrue
>becoz session only return the String not an object.
Preety Much a false statement made.
One can always store Objects as an Attribute inside the scope of session.
(could be valid when you talking in when you are working on client side cookies)
Where an Object could be an Instance of any class.
here is how you do that
first.jsp:
======
<%
Vector<String> vector = new Vector<String>();
vector.add("hello");
vector.add("how");
vector.add("are");
vector.add("you");
session.setAttribute("AttributeName",vector);
-
-
response.sendRedirect("second.jsp");
%>
second.jsp:
=========
<%
Vector<String> vector = (Vector<String>) session.getAttribute("AttributeName");
%>
Hope that might help both you guyz...:)
REGARDS,
RaHuL
# 6
:))
Ho come on...
the above example was given to demonstrate a way to do it.
forget using generics if you are working on JDK 1.4 or below.
if someone is too lazy to use their geneosity they might have to replace "<String>" with "" to work on similar code...
and i strongly believe
"if you are pertained to stick where you are,you'd stay the way you are"
hope there are no hard issues on this...
REGARDS,
RaHuL