Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to send an AJAX request to Struts Action?

 
C Brown
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a page that is displaying a SVG rendered chart and I am trying to convert that chart into an image for the user to download. I am using struts for the download action and a separate servlet for actually converting the SVG elements into an image (not sure if this is the best approach). Since there is so much information (tags and attributes) required for the SVG chart I decided to use AJAX to send smaller pieces of info back to the servlet in order to avoid an 'out of memory' error. My question is this, is it possible to have the AJAX function send the info to the download action instead of the servlet? I am using the Struts HTML tags for my form and I am not sure of how to write the URL for the AJAX request in order for it to go to the action. I ask because the download action usually gets executed before the file conversion is complete. Thanks,

Chris
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no difference between an Ajax request to an action and an Ajax request to a servlet (or whatever).

That said, I'm surprised you'd get an OOM error--if there are *that* many form/etc. elements on the page maybe it'd be best to get them the same way you got them when you displayed the JSP in the first place and avoid such a massive submit.
 
C Brown
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David,
I agree, what you said would be the easiest way of doing things, but I am using Dojo to create the chart and not sure if it is possible to get the data without it first being displayed. I thought I tried using the same call for the request in ajax and got an error, but maybe I mistyped something. I'll try again thanks.
 
C Brown
Greenhorn
Posts: 16
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tried to use the same URL but I got a 404 error. The tag for my form looks like this:

I tried to include '/fileDownload.do' in my ajax call (using Dojo):

Is this what you meant? Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <html:link> tag will do things like add the app context etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic