struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <>
Subject Re: Getting acknowledgment for an AJAX request
Date Tue, 23 Sep 2008 19:26:36 GMT
ManiKanta G wrote:
> Hi,
> I m practicing AJAX in S2. And in response to my previous mail, Dave replied
>> That's what Ajax does (loosely speaking): returns HTML fragments (or data as JSON,
XML, etc.). That's the point of it--so you don't have to return entire pages and refresh the
entire window.
>> So, If I want to acknowledge some AJAX request (say, '2 new records has
> been added') I just needed the count of how many rows got inserted/updated
> successfully or a flag indicating the success or failure of the request.
> And for this I m sure I don't need to return a jsp. How can be this done?
> through JSON? if yes, can some one point me to some resource to learn using
> JSON in S2?

If all you need to return is a number or true/false, simply write that 
to the response in your action method and return null (so Struts knows 
not to try executing any other results for the request). For more 
complex response data, the JSON plugin would be a good starting place. 
There's nothing stopping you from generating the response with a JSP, 
either, it's just not usually the easiest thing to do for an Ajax response.

The bottom line is that, once you understand what it is you want to 
return (a number, a boolean, a JSON data structure, etc.) the means by 
which you generate that response are up to you. Understand what the 
response ought to look like first, *then* worry about what your options 
are for generating it.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message