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 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi,

thanks for ur reply.what the problem is when i am trying to set the vector even it is giving me null when i try to retrieve it in any other page so can u plz give a brief desciption how to set my vector from servlet in a bean class or i have to first retrive the vector from servlet to jsp then i will set the vector in that jsp.

plz guide me.

thanks

paridaa at 2007-7-12 17:33:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

RahulSharnaa at 2007-7-12 17:33:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Hi Rahul,thanx for u'r comments and i agree that.i think that code is only working in java 1.5 and above version it's right.Bala
art84a at 2007-7-12 17:33:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

RahulSharnaa at 2007-7-12 17:33:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
hi rahul,i think u ll mistake me.i want to clear my doubts so that i am asking like that.Bala
art84a at 2007-7-12 17:33:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...