I have to use loading bar on selected actions in Struts2, & am using ServletActionContext
, but getting NullPointerException
.
ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
If I remove execAndWait
interceptor from xml configuration file, it works fine.
Some people suggested me to use SessionAware
. Why so ?
Is there any solution ?
The ActionContext
is ThreadLocal
and it doesn't have a request object when you run a background thread via execAndWait
interceptor .
If you use SessionAware
, then you should have servletConfig
interceptor on the stack to be able to set the session object to your action before the action is executed.
Solution: if you can get ServletRequestAware
to set a request object to the action and use servletConfig
interceptor prior the execAndWait
interceptor in the stack. If you need to create a custom stack you should keep the order.
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.