0

I need to share session variables across multiple war files. My project has 3 wars (lets call them war1, war2, war3) and once login is completed in war1, there are redirection links for war2 and war3 files. I need to share the same session username across all the three wars.

Currently I have used request.getSession().getServletContext().getContext("rootContextName").getAttrubute("sessionName") in war2 and war3 to get the sessionName from war1. But I am not sure if this is the right way to go about it.

I need to know if there is any other way possible to achieve the same.

Thank you in advance!

Edit: When I am logging in from war1 and traversing to war2 from browser1, the session values are set properly and I can access them. But when I am using the same URL of war2 in browser2, I am still able to see the session values set and able to get them. I dont want this cross-browser session sharing. Any suggestions are welcome! Thanks!

Pratik Kumawat
  • 146
  • 2
  • 14
  • If you are using Tomcat, see: https://stackoverflow.com/questions/665941/any-way-to-share-session-state-between-different-applications-in-tomcat and https://stackoverflow.com/questions/9436736/sharing-session-data-between-contexts-in-tomcat and from the official Tomcat documentation: http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html – Joey Ezekiel Jun 09 '17 at 10:19
  • @JoeyEzekiel, thanks for your reply. I am currently using the same method to set and get session values but what I want to know is that whether this way is safe or not? And is there any other way to achieve this. Thanks! – Pratik Kumawat Jun 09 '17 at 11:57
  • @JoeyEzekiel, And to add to it, when I am logging in from war1 and traversing to war2 from browser1, the session values are set properly and I can access them. But when I am using the same URL of war2 in browser2, I am still able to see the session values set and able to get them. I dont want this cross-browser session sharing. Any suggestion are welcome. Thank you! – Pratik Kumawat Jun 09 '17 at 14:11
  • That's definitely not right! Between tabs, yes but not across browsers. There has to be some error in the way your application is built! Avoid static references to any session data. First figure out if its the Tomcat that is causing the issue or if it is your code. – Joey Ezekiel Jun 19 '17 at 09:45
  • Thanks @JoeyEzekiel – Pratik Kumawat Jul 19 '18 at 07:10
  • This solved my problem https://stackoverflow.com/questions/665941/any-way-to-share-session-state-between-different-applications-in-tomcat Thanks @JoeyEzekiel – Pratik Kumawat Aug 28 '18 at 09:39
  • This solved my problem https://stackoverflow.com/questions/665941/any-way-to-share-session-state-between-different-applications-in-tomcat Thanks @JoeyEzekiel for suggesting. – Pratik Kumawat Oct 08 '18 at 11:43

0 Answers0