my dog learned polymorphism*
The moose likes Struts and the fly likes How to send an AJAX request to Struts Action? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to send an AJAX request to Struts Action?" Watch "How to send an AJAX request to Struts Action?" New topic
Author

How to send an AJAX request to Struts Action?

C Brown
Greenhorn

Joined: Jun 24, 2009
Posts: 16

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jun 24, 2009
Posts: 16

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

Joined: Jun 24, 2009
Posts: 16

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

Joined: Sep 29, 2008
Posts: 12617

The <html:link> tag will do things like add the app context etc.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to send an AJAX request to Struts Action?