• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2, Ajax, action is only called one time

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, seems I was right about the cacheing.

http://struts.apache.org/release/2.1.x/struts2-core/apidocs/org/apache/struts2/dispatcher/StreamResult.html
• 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>
</result>
</action>


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


code is working as intended.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic