I am working on Transaction Management application, and I am using Struts2. I have used internally a session for setting and getting values like
ActionContext.getContext().getSession().put("string", string);
Is there any limit or any disadvantage of using a session like this in the application?
Limit is the size of your computers physical memory.you dont store dynamic values in session because someone can modify them in the meanwhile , so store only those values in session which represent any user specific data or static values (i.e. which are not going to be changed while session exists).
Note : static here is not static keyword .
It's your size of the internal/physical memory of the system. The session is create a singleton class in your war file.The war file is stored in your Server. The server is in your C: folder in windows. So the session is depends on your physical memory.
There's no limit. The session in Struts 2 is implemented as a
Map
to simplify access to servlet session's attributes.I have written in this answer:
I know only one disadvantage if you get the session from the action context, it might return
null
. The solution is in this answer.The first method is preferred, as explained in the docs page, allows you use a session in tests.