Search code examples
javastrutshttpsession

Is it possible to store whole object in struts session?


I'm developing an struts App. In one of the actions I instantiate an object, once instantiated i need that object to be available in other actions for the user using the App.

Is there a way to store a whole object in the http session in Struts 1.3?


Solution

  • We can store and retrieve any object.

    In Action1 use:

      private ArrayList<Integer> obj= new ArrayList<Integer>();
      .............
      session.setAttribute("objname", obj);//to store
    

    In Action2 use:

      ArrayList<Integer> obj1= (ArrayList<Integer>)session.getAttribute("objname");//to retrieve
    

    Syntax:

     setAttribute(java.lang.String name, java.lang.Object value)