| Author |
Array as session attribute
|
Surendra Kumar
Ranch Hand
Joined: Jul 04, 2006
Posts: 87
|
|
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
Joined: Nov 24, 2005
Posts: 14685
|
|
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.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
As Satou pointed out, nothing will change anything that you store as a scoped variable.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Surendra Kumar
Ranch Hand
Joined: Jul 04, 2006
Posts: 87
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
|
Can you also post the HTML form that you're using to send the data from the browser to your servlet?
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
Also, how are you printing idList (how do you know that it's IDs separated with commas)?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
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
Joined: Nov 24, 2005
Posts: 14685
|
|
Are they being printed inside square brackets?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
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
Joined: Jul 04, 2006
Posts: 87
|
|
This is how the request params are going in the url: &VID=0%2C0&id=115956289325355100007%2C115956289325355100009
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
&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
Joined: Jul 04, 2006
Posts: 87
|
|
|
Then, how to get parameter value that contain multiple values of same parameter, and set in session?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
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.
|
 |
 |
|
|
subject: Array as session attribute
|
|
|