0

I just started using struts 2 last week, so the answer to my question may be obvious.

I have an opening form with submit that uses an action and executes method to get the data. Then, the only way I could get jQuery to work was to put an action and execute the method that just returns success and then I go onto my jQuery grid with a 3rd action.

whenever I try to execute my program on a browser, the only problem I have is that the JSON string is returned as a file. So when I call the getJSONResult action, it gives me a file with the JSON string in it, which I can open or download . .

Examples:
example 1
example 2

So I think it’s a configuration problem, but I can’t find it. I would be very glad if somebody could help me, thanks guys!

4

1 回答 1

1

The problem is likely not on the struts side, but on the HTML/JQuery side.

If you click the submit button, the browser wants to do something with the result (open it...). You want to prevent that from happening, and just get the result and handle it yourself.

I managed to use jQuery with struts, and was inspired by this blogpost. The handling of the result is explained there pretty well. You do not have to follow it completely, but it will steer you in the right direction:

http://mycodefixes.blogspot.be/2011/01/using-struts-2-with-json-and-jquery.html

于 2012-08-22T15:31:34.223 回答