recently I updated my struts2 version from 2.0.11 to the current 2.2.3. Unfortunately I have curious problems now which I was not able to solve so far.
When I try to get the ActionContext:
ActionContext context = ActionContext.getContext();
System.out.println("context: " + context);
The context is now null! The curious thing here is, that based on what the API says, it can't be null -> getContext API desc
It seems not to be a common problem, since I did not find one similar case via google. Since I just have the problem after updating the struts2 version, I tried to exchange different librarys, but I did not get one step further. Therefore I hope that someone of you can help me!
I have no more ideas what I can try to solve this problem.
Greetings oetzi
.
EDIT1:
Hello umesh awasthi! yes, it worked fine for quite a long time with the previous version. The log file unfortunately did not tell me much. Only that a NullpointerException occures when I try to access the ActionContext.getContext(); object.
This is an one code example where I use it
public CharServic开发者_如何学编程eImpl(){
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 am using the FilterDispatcher (However, I have to admit that I even did not know that there are different ones...)
By the way: I tried to log in during the last days over the function log in with stack exchange". I only get 3 "running points" but not a log in formular?! Now I used my gmail account for it, which was not what I actually wanted to do, but I did not want to keep you waiting for my reaction.
Try creating 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;
}
}
精彩评论