Session in Struts 2

Is this the correct way to store a value in a session in Struts2?

Map<String, Object> session = ActionContext.getContext().getSession();
session.put("user", "USERNAME");
+5
source share
1 answer

The SessionAware interface in struts 2.x, our Action class needs to implement the SessionAware interface in order to get the HTTP session behavior in our Action class.

If we implement the SessionAware interface, we need to override the setSession () method of SessionAware in our action class. If we implement our action class from the SessionAware interface, then the struts 2 controller does not enter the exact session object, but it does enter the Map object with the same behavior.

 Map m;
 public void setSession(Map m)
    {
        this.m=m;
    }

 public String execute()
    {
        m.put("user", "USERNAME");


        return SUCCESS;
    }
+1
source

All Articles