user3890872
user3890872

Reputation: 41

How to access action class session in another action class

How to access one action class session in another action class in Struts2?

public String execute()
{
    HttpServletRequest request=ServletActionContext.getRequest();  
    HttpSession session=request.getSession();  
    //System.out.println(" table  "+tid);
    //Map session = ActionContext.getContext().getSession();

    Map<String,Integer> s =(Map)session.getAttribute("table"+tid);  
    if(s!=null)
    {
        System.out.println("in if");
    for (Map.Entry<String,Integer> en : s.entrySet()) 
    {
            System.out.println(" in tableactio ");
    }

Upvotes: 0

Views: 1308

Answers (1)

Butani Vijay
Butani Vijay

Reputation: 4239

Please Note : Session is unique to browser not to action.

in struts2 you an get session using below code :

ActionContext.getContext().getSession()

Example: Getting userid stored in session:

int userId = Integer.parseInt(ActionContext.getContext().getSession()
                .get("userid").toString());

Upvotes: 1

Related Questions