• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question on session

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we place an arraylist into session?
i know how to place the string in session.in one interview they have asked this question
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer: YES... an ArrayList can be placed in session.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpSession.setAttribute's second argument type is java.lang.Object. Therefore, you can bind anything to session.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can place any Object in a Session but I truly recommend to store only java.io.Serializable objects.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx i was looking for the answer as well.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when iam retriving using getAttribute iam getting null
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic