Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass Vector to servlet from a jsp page?  RSS feed

 
Faxin Zhao
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a list of accounts stored in a Vector, and want to use session to pass it to a servlet, but in that servelt, the size of that Vector is 0.
What's the problem? How to fix it?
Thanks in advance!
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could *probably* use some more details on your question... How are you trying 'to use session to pass it to a servlet'?
 
Faxin Zhao
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tom.
In my jsp, I have these:
Vector orgAcctList = new Vector();
String curCode = "";
...(assign values to them)
session.setAttribute( "originalAccountList", orgAcctList );
session.setAttribute( "currencyCode", curCode );

Then in my servlet:
Vector getOrgAcctList = (Vector) session.getAttribute("originalAccountList");
String getCurCode = (String) session.getAttribute("currencyCode");

I can get the value of getCurCode, but not getOrgAcctList
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm.. looks like whatever you stored in that vector should be accessible when the servlet grabs the session attribute. Could you include your code where you're populating the vector?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code for putting the object in the session and retrieving it look ok. I'd put some System.out.println() statements in the jsp code to verify that it is actually populating the vector like you think it should.
 
Faxin Zhao
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a test in my testing jsp:
...(add value to vector)...
session.setAttribute( "originalDataList", originalDataList );
session.setAttribute( "newDataList", newDataList );
...
Vector getOrg = (Vector) session.getAttribute( "originalDataList" );
int sizeOfOrg = getOrg.size();
System.out.println("In jsp, org size="+sizeOfOrg);
for (int i=0;i<sizeOfOrg;i++)
{
System.out.println("org["+i+"]="+getOrg.elementAt(i));
}
Vector getNew = (Vector) session.getAttribute( "newDataList" );
int sizeOfNew = getNew.size();
System.out.println("In jsp, new size="+sizeOfNew);
for (int ii=0;ii<sizeOfNew;ii++)
{
System.out.println("new["+ii+"]="+getNew.elementAt(ii));
}
System.out.println("==============");


Then I saw the output:
In jsp, org size=1
org[0]=200412|FZ1234567|123456|null|Y|Y|null|Y|5|5432
In jsp, new size=1
new[0]=Document Cancelled

Then in my tesing servlet:
Vector orgDataList = (Vector) session.getAttribute("originalDataList");
Vector newDataList = (Vector) session.getAttribute("newDataList");
int sizeOfList = originalDataList.size();
System.out.println ("Step - 2.2 - size of org list="+orgDataList .size());
System.out.println ("Step - 2.3 - size of new list="+newDataList .size());

But I sill saw 0 in output:
Step - 2.2 - size of org list=0
Step - 2.3 - size of new list=0
 
Balan Raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the object that you put into session 'serializable' ??
I would check that first..

Just try simple Strings in the vector to see if its working!

-Rajesh
 
Faxin Zhao
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the simple String works.
Now I guess something not config correctly in websphere.
I have posted my question to WebSphere forum.
Thanks all for your help.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!