简体   繁体   中英

ActionContext.getContext() returns NULL

private Map<String, Object> session = ActionContext.getContext().getSession();

I am trying to use Session in Struts, But I'm getting this error.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke 
"com.opensymphony.xwork2.ActionContext.getSession()" because the return value of 
"com.opensymphony.xwork2.ActionContext.getContext()" is null

It was working perfectly before a few hours and my program was working fine. After some time my PC went blank and restarted and after restarting this error started to show up. I haven't changed my code a bit. Everything is the same but facing this problem.

I tried to use SessionMap of Struts but still got the same error message. I have tried changing the struts-core libraries and also tried a few solutions from Google but still doesn't solve this issue. Please provide a solution for this.

ActionContext is a container placeholder for the action invocation, more detailed explanation is here .

There's a lot of reasons when an action context could be null . You are starting another thread, or modify existing one, or it's just not created yet.

To get a SessionMap there's another approach. Let your action class to implement SessionAware and make sure you have configured a default interceptor stack for the action. After that the session map should be injected to the action instance. More about it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM