Indresh Chadha wrote:
I need to download a file from the server using AJAX & Struts.
Is this possible?
No, it's not... well, assuming if by AJAX you mean using XMLHttpRequest,
but since AJAX is a technique, arguably using things like hidden frames
is still AJAX, and with that you could download a file certainly.
But, assuming you mean XMLHttpRequest, or some library that uses it
underneath, then no, you can't do this. The reason is that
XMLHttpRequest gives you a chunk of text, or an XML DOM object, but in
neither case can you write this to disk, or tell the browser to open it
with an appropriate handled application.
There are some nifty implementations out there using a hidden iFrame
that makes it *look* just like what you'd expect an AJAX-based download
to look like, but it's not, strictly speaking, a download via AJAX,
which isn't (currently) possible).
Frank
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Author of "Practical Ajax Projects With Java Technology"
(2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
(2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!
Frank W. Zammetti wrote:
No, you don't need to implement StrutsFileDownload... What your doing
should work fine... Can you throw together a quick, simple application
that is nothing but a single Action that writes out "ok" to the response
and returns null? See if that works... if what you describe is
accurate, it sure sounds like something prior to your Action is getting
the output stream, which probably should not be happening.
Frank
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: [EMAIL PROTECTED]
Author of "Practical Ajax Projects With Java Technology"
(2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
(2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!
Jon Wynacht wrote:
Hi Mike,
Yup. I did that and no error is thrown now, however I don't get the
download anymore....I'm thinking I need to implement StrutsFileDownload
instead and that's my link? Thoughts?
Jon
On May 28, 2007, at 8:21 AM, Mike Baroukh wrote:
Hi.
Maybe it has worked before, but I think you actually make an error :
If you already send a stream back to the client, it's not logic to
return "mapping.findForward()" because nothing else can be send to the
browser at this point.
You should simply return "null" ...
Mike
Jon Wynacht a écrit :
Hi,
I asked this question of the POI user mailing list but it's probably
a question for this list. If you don't know what POI is, check it out
here:
http://jakarta.apache.org/poi/
I used to run Struts 1.2.9, POI 2.5 and could generate Excel files
from a servlet and download them without issue. I recently upgraded
to Struts 1.3.5 and POI 3 and it looks like I broke that capability.
I'm getting the following error:
java.lang.IllegalStateException: getOutputStream() has already been
called for this response
I've searched through the Net and the archives here for info but
nothing really seems to fit for my situation; it's mostly JSP.
I'm calling an Action servlet which makes a call to the model and
gets some data, creates a new workbook and then does this:
<snip>
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition",
"attachment;filename=\"attendees.xls\"");
response.addHeader("Content-description", "Event
Attendees");
ServletOutputStream stream =
response.getOutputStream();
wb.write(stream);
stream.close();
...
forward = "SUCCESS";
...
return mapping.findForward(forward);
</snip>
It's what I did before I upgraded and things worked fine. Now they
don't
Any ideas? Am I missing something really obvious or was I bending the
rules a bit and taking chances with my data in my previous config?
Cheers and thanks,
Jon
Jon Wynacht
[EMAIL PROTECTED]
http://www.objectevolution.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Mike Baroukh
---
Cardiweb - 31 Rue de Mogador Paris IXeme
06 63 57 27 22 - 01 53 21 82 63 - Jabber: [EMAIL PROTECTED]
http://www.cardiweb.com
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Jon Wynacht
[EMAIL PROTECTED]
http://www.objectevolution.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--No virus found in this incoming message.
Checked by AVG Free Edition.Version: 7.5.472 / Virus Database:
269.8.0/821 - Release Date: 5/27/2007 3:05 PM
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]