0

How to share attributes between sessions?

asked 2020-12-01 01:20:37 +0800

softteam gravatar image softteam
120 8

updated 2020-12-02 20:13:58 +0800

Hi,

I would like to know the best way to get an attribute of one session from another. We are working with different projects (.war) and every project has his own session. I want to set an attribute that represents the style of the first .war and then get that attribute from another session created by a second .war.

Which is the best way to do this? Can the second session get the attribute from the first one? There is other variable that the two sessions share? We use Tomcat.

Thank you,

Javier

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-12-01 17:34:09 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

There are definitely ways to share data between war files... however the servlet specification doesn't provide such. Since ZK is built on top of the servlet spec there isn't a mechanism within ZK either.

https://stackoverflow.com/questions/665941/any-way-to-share-session-state-between-different-applications-in-tomcat

Instead you'll have to integrate solution outside the war files (e.g. JNDI, redis, ehcache) or a DB to share data between war files.

If the information isn't sensitive you might as well just set a cookie at root path '/' and read the cookie value from both web applications.

link publish delete flag offensive edit

Comments

About cookies:

I set sessionCookiePath="/" in <Context> in server.xml How to set and read this cookie value in java?

Thank you!

softteam ( 2020-12-02 22:51:43 +0800 )edit
0

answered 2020-12-03 15:34:48 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

updated 2020-12-03 15:35:14 +0800

No need to change the session cookie configuration. Instead you add and get your own cookie using HttpServletResponse#addCookie(cookie) & HttpServletRequest#getCookies()

From inside your ZK applications you can get the request and response objects via:

HttpServletRequest request = (HttpServletRequest)Executions.getCurrent().getNativeRequest();

HttpServletResponse response = (HttpServletResponse)Executions.getCurrent().getNativeResponse();
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-12-01 01:20:37 +0800

Seen: 13 times

Last updated: Dec 03 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More