wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts 2, Ajax, action is only called one time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2, Ajax, action is only called one time" Watch "Struts 2, Ajax, action is only called one time" New topic

Struts 2, Ajax, action is only called one time

m pa

Joined: Apr 17, 2013
Posts: 17
I am using in Struts 2 with Ajax. The javascript function that creates the http request is called every 5 seconds by:

the url is mapped in struts.xml to a method in an action, I have a breakpoint in the method that is reached but it only happens once - it should be called every 5 seconds.
The method returns some text with the value of a counter that is incremented on each call but the counter value does not change - no surprise since the method's breakpoint is not reached.

I am reasonably sure javascript in the jsp is correct - I modified the function that deals with Ajax response to alter the url to a bad value and I get struts error the action request url is being handled by struts.

It seems to me that there is some "cacheing" going on in struts, pseudo code:

if action has executed return action results
else call action

Just to reiterate, the method should be called every 5 seconds but is only called once.

my struts entry:

The action class method, gets called one time:

and the jsp
m pa

Joined: Apr 17, 2013
Posts: 17
ok, seems I was right about the cacheing.

• allowCaching if set to 'false' it will set the headers 'Pragma' and 'Cache-Control' to 'no-cahce', and prevent client from caching the content. (default = true)

so fixed by:
<action name="helloAjax" class="com.mp.action.HelloWorldAction" method="helloAjax">
<result name="success" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
<param name="allowCaching">false</param>

oh, and the count variable needs to be a class variable:

code is working as intended.
I agree. Here's the link: http://aspose.com/file-tools
subject: Struts 2, Ajax, action is only called one time
Similar Threads
Ajax javascript not recieving responseText from Struts
Struts 2: how to set response for ajax function call?
Strut-Ajax - display states when Country selected
AJAX part in jsp is not functioning with IE 6.0
Page section does not update after call of a4j:support in IE 9