| Author |
question on session
|
pvsr rao
Ranch Hand
Joined: Oct 05, 2005
Posts: 102
|
|
can we place an arraylist into session? i know how to place the string in session.in one interview they have asked this question
|
 |
Ola Daniel
Ranch Hand
Joined: Jul 27, 2005
Posts: 105
|
|
|
Short answer: YES... an ArrayList can be placed in session.
|
SCJP 1.4, SCWCD 1.4
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
HttpSession.setAttribute's second argument type is java.lang.Object. Therefore, you can bind anything to session.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Originally posted by Ben Souther: HttpSession.setAttribute's second argument type is java.lang.Object. Therefore, you can bind anything to session.
If you are using Java 5 you can also bind primitives becasue of the auto boxing feature.
|
Groovy
|
 |
pvsr rao
Ranch Hand
Joined: Oct 05, 2005
Posts: 102
|
|
please send me the samplecode for placing an arraylist into session. i have tried but iam getting classcastexception ArrayList a= new ArrayList(); a.put("aa"); HttpSession.setAtrtribute("Arraylist","a"); please reply to this
|
 |
Darren Edwards
Ranch Hand
Joined: Aug 17, 2005
Posts: 69
|
|
The code you have posted will not cause an exception (nor will it run as HttpSession is not a variable, it's a class). [ June 20, 2006: Message edited by: Darren Edwards ]
|
 |
Kavitha Govindaraj
Greenhorn
Joined: May 27, 2004
Posts: 28
|
|
Hi try this.. Syntax: void setAttribute(java.lang.String name, java.lang.Object value) Binds an object to this session, using the name specified. A simple search in Servlet API will solve your problem. So do some basic work before asking help from anyone. Sorry to be too hard. But that will really help you.
|
Thanks <br />Kavitha G <br />SCJP
|
 |
Jaime M. Tovar
Ranch Hand
Joined: Mar 28, 2005
Posts: 133
|
|
|
You can place any Object in a Session but I truly recommend to store only java.io.Serializable objects.
|
She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
|
 |
smith stevenson
Greenhorn
Joined: Jun 20, 2006
Posts: 1
|
|
|
Thanx i was looking for the answer as well.
|
 |
trinadh reddy
Ranch Hand
Joined: Sep 22, 2005
Posts: 58
|
|
|
when iam retriving using getAttribute iam getting null
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Originally posted by trinadh reddy: when iam retriving using getAttribute iam getting null
Why would you post such a short statement to the end of another thread? If reading the discussion in this one didn't solve your problem, start a new one with a a well written question. By well written, I mean, explain what you've done. Use code examples if necessary (be sure to use UBB code tags if you post code). In general, if you take some time and show some effort you stand a much better chance of getting a useful answer.
|
 |
 |
|
|
subject: question on session
|
|
|