I was wondering if it could be possible to change some fields for a struts2 action from another action. For example, I have Class1 Action with field string1, and I want to change it from another action, Class2.
public class Class1 extends ActionSupport{
private String string1="old String";
}
public class Class2 extends ActionSupport{
public String execute(){
Class1 class1=new Class1();
class1.setString1("new String");
}
}
In struts1, one could take all ActionForms from session. In struts2 they are no longer available on session, from the moment that there are no more action forms. Thanks!
Struts2 action instances are created when the request matches action mapping for the action.
New instance is created each time.
They live until the request processing ends and after that are inaccessible.
Hence you’d have to somehow map a request to two actions at the same time, which is AFAIK impossible or do some other trickery which would go against Struts2 model.
If you need to pass information from one action to another, you have some options, ie: