最近,我将我的struts2版本从2.0.11更新到了当前的2.2.3。不幸的是,我现在有一些奇怪的问题,到目前为止我还不能解决。
当我尝试获取ActionContext时:
ActionContext context = ActionContext.getContext();
System.out.println("context: " + context);上下文现在为空!这里奇怪的是,根据API所说的,它不能为空-> getContext API desc
这似乎不是一个常见的问题,因为我没有通过谷歌找到一个类似的案例。由于我只是在更新struts2版本后遇到了这个问题,所以我尝试交换不同的库,但我没有更进一步。所以我希望你们中的一些人能帮助我!
我不知道我能试着解决这个问题。
问候oetzi
。
EDIT1:
你好,umesh!是的,在之前的版本中,它在相当长的一段时间内都工作得很好。不幸的是,日志文件并没有告诉我太多信息。只有当我试图访问ActionContext.getContext();对象时才会发生NullpointerException。
这是我使用它的一个代码示例
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");
}
}@史蒂芬·贝尼特斯:我正在使用FilterDispatcher (然而,我必须承认我甚至不知道有不同的……)
顺便说一下:我试着在过去的几天里用堆栈交换的log函数登录。我只得到了3个“运行点”,而在formular中却没有得到一个log?!现在我使用了我的gmail帐户,这并不是我真正想要做的,但我不想让你等待我的反应。
发布于 2015-04-17 15:07:12
尝试使用ServletActionContext创建ActionContext
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;
}
}https://stackoverflow.com/questions/7300739
复制相似问题