Ajax, Struts and a Null Pointer
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 retu开发者_StackOverflow社区rns 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!
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.
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.
精彩评论