Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array as session attribute

 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servlet where I am getting an array of param values, and putting this array in an session attribute.
Later in another servlet, I'm getting this attribute as an array, but I am getting single value with comma seperated values.

what might be the problem?
Isn't array returned? Why is it returened as single value?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
putting this array in an session attribute.

Are you sure this is not a comma separated string that you put in you session ? Please show us how you first get the array, how you put it in session, and how you get it back.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Satou pointed out, nothing will change anything that you store as a scoped variable.
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I did:
1st servlet:


2nd servlet:


In this 2nd servlet, I got idList as a single String with id's separated by commas.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you also post the HTML form that you're using to send the data from the browser to your servlet?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, how are you printing idList (how do you know that it's IDs separated with commas)?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Surendra Nichenametla:

In this 2nd servlet, I got idList as a single String with id's separated by commas.


Are they being printed inside square brackets?
[one, two, three]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are they being printed inside square brackets?

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:



It wasn't really meant as a joke.
I don't know what server the Original Poster (OP) is using or how he's printing the array.

I know that the toString method in java.util.Arrays, for Java 5 will actually print out the contents of the array instead of the traditional
[Ljava.lang.String;@10b62c9 that we're all used to:


I'm just wondering if he really is dealing with a single string or if whatever he's using to print the array is using Arrays.toString.
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how the request params are going in the url:

&VID=0%2C0&id=115956289325355100007%2C115956289325355100009
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just wondering if he really is dealing with a single string or if whatever he's using to print the array is using Arrays.toString.

I understood what you meant, that's why I put a smile. No offense of course.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
&VID=0%2C0&id=115956289325355100007%2C115956289325355100009
This would not be interpreted by a servlet as an array.
It's a URL encoded set of numeric characters with a comma in the middle.

For an array, of ids, you would need to send:
&VID=0%2C0&id=115956289325355100007&id=115956289325355100009
[ October 04, 2006: Message edited by: Ben Souther ]
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then, how to get parameter value that contain multiple values of same parameter, and set in session?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, updated post while you were responding.

Here:
For an array, of ids, you would need to send:
&VID=0%2C0&id=115956289325355100007&id=115956289325355100009
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:

I understood what you meant, that's why I put a smile. No offense of course.


Ahh, I should have known.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic