Access request session application objects Struts 2

Access request session application objects Struts 2

You could access all scope attribute maps from ActionContext instance only you have to be careful not use constructor of Action class to get ActionContext.getContext() this may return return null for getSession() object:

package com.javahonk.action;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ActionContext;

public class GetHttpServletRequestAction {

	@Action(value = "/Accessingservletcopes")
	public void downloadCSVFileAction() throws Exception {

		Map attr = (Map) ActionContext.getContext().get("attr");
		attr.put("key","value");
		 
		Map application = (Map) ActionContext.getContext().get("application");
		application.put("key","value");
		 
		Map session = (Map) ActionContext.getContext().get("session");
		session.put("key","value");
		 
		Map request = (Map) ActionContext.getContext().get("request");
		request.put("key","value");

	}

}
  • For details please visit struts 2 official tutorial here

Leave a Reply

Your email address will not be published. Required fields are marked *