How many sessions can be managed by an Java Application in Struts 2?

后端 未结 3 1806
你的背包
你的背包 2021-01-26 09:31

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.g         


        
3条回答
  •  遥遥无期
    2021-01-26 09:52

    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:

    The SessionMap is specifically designed for the purposes if you want to have access to the servlet session attributes. So, the user is able to keep a synchronized collection of objects in session and use it instead of HttpSession directly.

    I know only one disadvantage if you get the session from the action context, it might return null. The solution is in this answer.

    There are two methods to obtain a session map to the action:

    1. Implement SessionAware. By default the session map is populated on action call. This is a preferable way.
    2. Get a session map from the action context. This way you should make sure the request is handled by the Struts2 filter.

    The first method is preferred, as explained in the docs page, allows you use a session in tests.

提交回复
热议问题