• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session sharing problem  RSS feed

 
K G Ramya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My team is developing a Web application using JSF & Hibernate. While testing for concurrency from different machines we found out that the Session is getting shared between the two browsers. This happens randomly & hence I am left clueless.

Could anyone help me out on this.

Regds
Ramya.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A session is something that doesn't exist on the client side - it's created and kept on the server side (which is a good thing, because that protects it from arbitrary malicious modifications). What is actually being passed around clients is the session ID, which is a "magic" identifier that helps the appserver retrieve the proper session object. This is either passed in cookies (if enabled) or appended to the site's hyperlinks (URL rewriting).

I don't know if there's a formal spec on how that stuff should be passed around or not. Usually, I want the same session in all windows (or, in my case, on all tabs, since I use FireFox tabbed browsing.

But what you said was that the session is being shared between 2 different machines, which implies 2 different users, and that's usually not good. My guess is that you're not doing the URL rewriting properly, since cookies are supposed to be prtoected better than that. In JSF, normally this wouldn't be a problem - assuming you're using things like the JSF commandLink tags - since they manage that stuff for you. For manually-created hyperlinks, you'd have to remember to invoke the URL rewriter yourself.

Recommendation: get some "show page source" listings of the pages where the illicit session-sharing is happening and look to see what URLs are being generated. Then cross-check them back against the original JSF page source.
 
K G Ramya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim.

I did further research on the issue . Please find the details below:

Our page composes of three beans - 1 for Header, 1 for Navbar & 1 for Body.
We have the Header & Navbar jsps as includes in the Body.jsp.

When the user hits on the save button in the Body, the details have to get saved in the database. Upon successful updation the Header & the NavBar needs to get refreshed with new values. To achieve this functionality we were calling the refresh methods in the beforeRenderResponse() methods of the Header & NavBar. I guess that, since this method was getting called multiple number of times we had this data sharing problem. On commenting out this call it works fine.

But now I donot know how to call the refresh methods of Header & the LeftNav after Body.init() :-( .. Since we have included the Header first in the jsp the container calls the Header init methods even before the Body.init().

To be precise,

I would want the control flow to be --
Body.init(), leftnav.refreshData() & Header.refreshData() etc..
But currently the order is -- Header(), leftnav() & then Body.init() etc ..

Hope i've put it down clearly.

Thanks
Ramya.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a variant of the problem of having multiple forms on a JSF page, which caused a lot of problems in early JSF implementations.

In theory, like a good MVC app, any changes in any of the beans backing the page should "instantly" update in the page (view). By "instantly", since we're talking a synchronous protocol (HTTP), that would be the next time that the server updated the page. Which normally would happen when you click the "Save" button.

In orther words, it's possible you're trying a complex solution for a problem that's expected to solve itself without any explicit action required on your part. Or, you may be having issues with an older JSF implementation (or a bug in a newer version). You might google for "multiple form jsf" and see if anything useful comes up. Even if the navigation objects aren't in forms, the same general concepts apply.
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway,

But what you said was that the session is being shared between 2 different machines, which implies 2 different users, and that's usually not good.


but actually she meant two browsers not two different machines.


My team is developing a Web application using JSF & Hibernate. While testing for concurrency from different machines we found out that the Session is getting shared between the two browsers. This happens randomly & hence I am left clueless.


Are you trying to open another browser using New from File Menu in IE. or using ctrl + N.

In that case, there is very much possiblity for session to get shared.
 
K G Ramya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Dilip. Tim has got it right. I meant two different machines only.
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. Sorry for misunderstanding.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!