Struts2: ActionContext.getContext (); returns null

I recently upgraded the version of struts2 from 2.0.11 to the current version 2.2.3. Unfortunately, now I have curious problems that I have not yet been able to solve.

When I try to get an ActionContext:

ActionContext context = ActionContext.getContext(); System.out.println("context: " + context); 

The context is now zero! Curiously, based on what the API says, it cannot be null -> getContext API desc

This does not seem to be a common problem since I did not find one such case via google. Since I had a problem after upgrading the version of struts2, I tried to exchange different libraries, but I did not take another step further. Therefore, I hope that one of you can help me!

I have no more ideas that I can try to solve this problem.

Hi Oetzi

.

EDIT1:

Hi Umush awasthi! yes, it worked perfectly for a long time with the previous version. Unfortunately, the log file did not tell me much. Only this NullpointerException exception occurs when I try to access ActionContext.getContext (); an object.

This is one example code in which I use it

 public CharServiceImpl(){ ActionContext context = ActionContext.getContext(); //currently it crashes here since the context variable is null Map<String,Object> appCon = context.getApplication(); if (appCon != null){ charIdsToUpdate = (ArrayList<Integer>) appCon.get("charIdsToUpdate"); } } 

@Steven Benitez: I use FilterDispatcher (However, I have to admit that I didn’t even know that there are different ...)

By the way: I tried to log in in recent days through the log in function with stack exchange. "I get only 3" working points ", but not the log in formular ?! Now I used my gmail account for this, which I didn’t want to do, but I didn’t want you to wait for my reaction.

+4
source share
1 answer

Try creating an ActionContext using ServletActionContext

 class Abc implements ServletRequestAware { HttpServletRequest request; public CharServiceImpl() { ActionContext actionContext = ServletActionContext.getActionContext(); } public void setServletRequest(HttpServletRequest request) { this.request = request; } public HttpServletRequest getServletRequest() { return this.request; } } 
0
source

All Articles