struts2: ActionContext.getContext();返回空值

发布于 2024-12-02 15:57:12 字数 1280 浏览 0 评论 0原文

最近我将struts2版本从2.0.11更新到了当前的2.2.3。 不幸的是,我现在遇到了一些奇怪的问题,到目前为止我还无法解决。

当我尝试获取 ActionContext 时:

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

上下文现在为空!这里奇怪的是,根据 API 的说法,它不能为 null -> getContext API desc

看来这不是一个常见问题,因为我没有通过谷歌找到类似的案例。 由于我刚刚更新struts2版本后出现问题,我尝试交换不同的库,但没有更进一步。 因此,我希望你们中的某个人可以帮助我!

我不知道我可以尝试什么来解决这个问题。

问候 奥茨

编辑1:

你好,umeshawasthi! 是的,它在以前的版本中运行了很长一段时间。不幸的是,日志文件没有告诉我太多信息。只是当我尝试访问 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");
    }
}

@Steven Benitez: 我正在使用 FilterDispatcher(但是,我必须承认我什至不知道有不同的......)

顺便说一句:我在过去几天尝试通过“使用堆栈交换登录”功能进行登录。我只得到 3 个“跑分”,但没有登录公式?! 现在我用了我的 Gmail 帐户,这不是我真正想做的,但我不想让你等待我的反应。

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 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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等你爱我 2024-12-09 15:57: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;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文