• 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

access objects in a session

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JSP1 --> Action1 --> JSP2 --> Action2 --> JSP3-->Action3-->JSP4, we have
Form1Bean, Form2Bean, Form3Bean matching JSP1, JSP2, JSP3.

We need to carry over the information from JSP1(Form1Bean) to 2nd and 3rd page and more.. It seems the easiest way is to put scope="session" in the "action" tag in config-struts.xml. But besides doing that, do I need to explicitly write "session.setAttribute("Form1", Form1Bean);" (or explicitly do setAttribute() for every object I want to carry over pages) ? I am wondering if I only put "scope=session" in xml and skip doing this "session.setAttribute", can I still access "Form1Bean" in "Action3" class ?
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can place the form bean in session by specifying the action mapping's 'scope' attribute to 'session'...e.g scope="session". the form bean mapped to the action mapping will be placed in the session scope. remember to clear the form values out when you are done with them.
 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by alan do:
you can place the form bean in session by specifying the action mapping's 'scope' attribute to 'session'...e.g scope="session". the form bean mapped to the action mapping will be placed in the session scope. remember to clear the form values out when you are done with them.



thanks. since we usually don't need ALL of the information from a form, I want to selectively store some information and carry them over pages. Thus, I want to use session.setAttribute() in the Action classes. It should work, right ?
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as long as you clean out ALL the session values upon a successful action, yes. be careful not to over storing objects in session. session is not where large amount of data should be persisted. this impacts performance severely if improperly used.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Instead of using multiple forms, try to use a single bean which holds all the fields over jsp1,jsp2.. , use the single bean in session scope it works perfect.

Coming to cleaning, create another action which cleans the form before displaying the form for first time.


Srilakshmi
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
putting everything into 1 form bean will add major complexity to validation, especially if validation is declarative. doing so only make sense for multi-page forms, not for a case where ONLY selective values are passed from 1 form to another.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by alan do:
as long as you clean out ALL the session values upon a successful action, yes. be careful not to over storing objects in session. session is not where large amount of data should be persisted. this impacts performance severely if improperly used.



Interesting. What if the large object is stored in HttpRequest ? session costs memory resource, but doesn't HttpRequest cost too ?
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
objects in requests are stored once then destroyed per each completed request and DO NOT reside 'persistently' in the server memory. server memory is therefore 'reused' at each request. imagine having thousands of same objects per thousands of user sessions, each with large amount of data...all stored in your server memory...hence the necessary clean up when you're done with objects in session.
 
Your mother is a hamster and your father smells of tiny ads!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic