• Post Reply Bookmark Topic Watch Topic
  • New Topic

sending Vector Object from servlet to JSP page

 
Mahesh Pinnamaneni
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai buddies,
i am having a servlet which gets the user information to process and this information is also used in other JSP page.so how can i forward this JAVA Object, i mean Vector object to JSP page or Servlet.
thanks
regards,
Mahesh
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my prj I tried with request.setAttribute it was nt working
and so i used session.setAttribute(Object)
Srini
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, place it into session.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But also make sure u remove it ..
):
Srini
 
Mahesh Pinnamaneni
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works fine.i don't know how fast it will work with huge data that is stored in Vector.is there any other alterntive for this.
thanks for ur reply,
regards,
mahesh
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by srini vasan:
In my prj I tried with request.setAttribute it was nt working
and so i used session.setAttribute(Object)
Srini


Hey Srini,

this is not fair to say that it was not working with
request.setAttribute(). more important is why it was not working.

it was not working because you set it in request scope. when user requests server once and get the response then after gettin response that request becomes invalid. if user requests server again it would be a brand new request.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by srini vasan:
But also make sure u remove it ..
):
Srini


yeah you can but you really need not. because it sounds like session scope info, and it would automatically destoryed with session.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi adeeel,

If i set it in the request scope in a servlet which in turn calls y.jsp . this object shd be available in y.jsp ..
request.getAttribute works for some objects ... I was even hunting the reason for it ..
May be i'm going in a wrong way ...

i mean if you set any Attribute in the servlet like request.setAttribute("Name","aaa") and if u use request.getAttribute("Name")in y.jsp i was able to get the value in y.jsp ..

Srini
[ October 04, 2004: Message edited by: srini vasan ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean it is working fine with the String but not with the Vector.

could you paste some relevent code snippets.
[ October 04, 2004: Message edited by: adeel ansari ]
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
httpServletRequest.setAttribute("Fdt",httpServletRequest.getParameter("desd")); --> this works

Hashtable reversalStatus = new Hashtable();
request.setAttribute("reversalStatus",reversalStatus); --> not working
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wht result are you getting? i am assuming you are writing correct syntax, with no typo mistakes and no case mistakes.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep .. i'm using the correst case ...
i'm getting "null" ..
I'll again check with a sample snippet ..
and send you the whole code ...

Srini
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes .
I have this code in jsp ...

java.util.Hashtable test = new java.util.Hashtable();
test.put("debug","dbg");
request.setAttribute("hash",test);

But the result of the code request.getAttribute("hash") is null in the servlet. i'm sorry previously i said this happens when a servlet is calling a jsp .. but it's other way round.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so,

we dont do request.setAttribute() inside jsp because when we submit our request to server it would be a brand new request. you can say a virgin request. the previous request becomes invalid. and then if you try to do request.getAttribute() inside your servlet or some other normal class then you get nothing but a null.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hummmmmmmmmmmm
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not set something in the request object in a jsp which calls a servlet after a round trip from the browser back to the servlet. Once the request has been output, the request object and all it's attributes are out of scope.

If however, you are calling a servlet from a jsp without a round trip something is really wrong with your design.
[ October 04, 2004: Message edited by: Kerry Wilson ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!