• 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

how can we use struts to issue a session scope preparation ?

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I create a session-scope object when user session is created in the struts ?

Say, I have a variable which need to be created when session is created. In the plain servlet, we can write a session listener to issue a session scope preparation, for example, getting a datasource.

Now I try same way in Struts, but it doesn't work. I guess, Strtus create session even before it passes events to session listener, so we can't see any output. But we tell the variable is being added to session.

Anyway, how can we use struts to issue a session scope preparation ?

Thanks
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that what you are describing is usually done in the InitialAction, or whichever action the user first enters in the application.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at Rick Reumann's site. He as lots of good examples, all well annotated:

http://www.reumann.net/struts/lesson2/step9.do

Good luck.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kevin Judd:

http://www.reumann.net/struts/lesson2/step9.do



Thanks, Kevin. I have read this link. I realize one difference.

What that link did is , "Before we forward directly to the employeeForm.jsp " ...., then it does some session-scope setup. But the problem is , user has to invoke that /setupEmployeeForm.do, then it will work. Now I have to do this session-scope setup without any user's interaction, just like in Java, we have a globe static variable during compilation.

This is my problem.

Thanks.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:
I think that what you are describing is usually done in the InitialAction, or whichever action the user first enters in the application.



Thanks, Marc, which file is InitialAction in, so that I can extend that class file? Do you have some examples or link ?

Thanks
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An InitialAction is one that you create. It is like a SetupAction for the user's session.

Most often, it is used as the single entry point into an application (the first one the user enters). Sometimes the welcome page of a WebContext does an automatic redirect to such an action.

You can't have a session-setup without user interaction as you described. If a user does not enter [or interact with] an application they do not get a session.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After searching web and reading your guys post, I found these two solutions for preparing for session-scope variable.

1. use traditional session event listener. When page is loaded up first time, Struts always create a session for the user, even before it gets form bean variable value. In the session listener, we can issue some data, for example, jdbc connection.

2. extends RequestProcessor, override its method processPreprocess(...). When each time user click some action, it will always run processPreprocess() firstly. So we can do something there, for example, JDBC connection.

If anything wrong, please correct me. This is just my research.

Thanks.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic