Ajax、Struts 和空指针
我最近开发了一个简单的ajax 搜索。我的服务器中的整个代码都使用Struts,所以我不得不使用一种有点麻烦的编程方式。我的 main 方法返回一个 ActionForward。我的编程方式是将文本发送给客户端,然后向前返回一个空操作。
这非常有效。
...除了,它会在日志中生成空指针错误。而我们的生产日志通常会在每次发生错误时发送一封电子邮件。我怎样才能摆脱这个错误?还有其他方法吗(不涉及其他框架)?
谢谢!
I've recently developed a simple ajax search. The whole code in my server is using Struts, so I had to use a somewhat cumbersome way of programming. My main method returns an ActionForward. I programmed in a way that I would send the text to the client, and then return a null action forward.
This works perfectly.
...except, it generates a Null Pointer error in the log. And our production log usually sends an email every time an error occur. How can I get rid of this error? Is there any other way (that doesn't involve another framework)?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您说“主要方法”时,您是指您的操作类吗?如果这是通过 ajax 调用的,您可以将返回类型设置为 void。
When you say your "Main method" are you refering to your Action Class? If this is called via ajax, you can set your return type to void.
NPE 的原因可能存在于您的应用程序中,而不是 struts 中。今天我发现自己也遇到了同样的问题,非常困惑。 Struts 支持返回 null ActionForward,因此没有理由获取 NPE。
所以我深入研究了 NPE,发现它是由属于我们应用程序的一个类抛出的。该类继承了struts DispatchAction 类,并且又被我们应用程序中的所有操作类继承。
长话短说,虽然 struts 支持 null ActionForward,但后代类却不支持。一旦我调整了后代类来处理空值,NPE 就消失了。
The cause of the NPE might exist in your application, not in struts. I found myself facing the same issue today, and was really puzzled. Struts supports returning a null ActionForward, so there is no reason to get an NPE.
So I dug into the NPE and found that it was being thrown by a class belonging to our application. This class inherits the struts DispatchAction class, and is in turn inherited by all the action classes in our application.
To make a long story short, although struts supported a null ActionForward, the descendent class did not. Once I tweaked the descendent class to handle null values, the NPE went away.