• 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

Multiple Client Session Handling in Struts

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have created a simple struts application for which I am supposed to handle multiple sessions.

The application works very well. But the problem is, the session attributes get swapped when multiple users access it.
For example, UserA logs in, username of UserB is shown on Header. UserB wants to view UserC's profile, profile of UserA is displayed.

I am unable to find where the problem exists.

Please help. I am using Struts 1.1, Tomcat 5.0 and JDK 1.4.

Probably I have not done a good session management. Please let me know how do we start a session after logging in the application and how do we manage them for individual use.

Thanks.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are these users A, B & C logged in from the same browser?

Are you resetting the session when some user logs in and it finds old unwanted session?
 
Aditya Bhakay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Till now I am concerned about different users logged in the application from their own machine, means for this example, 3 individual machines logging in the application from any location.

Consider:

UserA -> IE -> Web Application
UserB -> Firefox -> Web Application
UserC -> Safari -> Web Application
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you invalidating your sessions properly ? Keeping everything in sessions is considered a bad design and might face problems.

I will suggest you to use request.setAttribute and fetch data using request.getAttribute or store data in database and then fetch on next request.

 
Aditya Bhakay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Absolutely Correct!!! That's why now I am using request.setAttribute() at most places.

Still I am confused about setting session attributes like user_name, user_id, role_id, application_skin_id attributes after logging in.

These are compulsory attributes as I am going to use these till the user's session exists, as you can figure out easily by names.
I am using the following straight away:

HttpSession session=request.getSession("false")
request.getSession.setAttribute("user_name")=loginobject.getUserName();
request.getSession.setAttribute("user_id")=loginobject.getUserId();
...

Is this a correct approach or I should do something else? Please suggest.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is your loginobject declared?

The only way I could see session data getting overwritten across browsers is if you have actions with instance variables.
 
Aditya Bhakay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
loginobject is just an action form bean with getters and setters. It is declared in other package but I am using this kind of beans to transfer data between action to business, business to DB layer and vice-versa.

I am doing following:

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's not an instance variable (which it doesn't appear to be from the code above, although it isn't a complete code snippet), then something else is wrong. I'm skeptical it's a Struts issue, since people have been using session in Struts for a pretty long time with no issues like this.

Can you restate the problem? (Not just repeat what you said before, but say it all over again--sometimes that helps.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic