[opencms-dev] Download a file from administration point

Paul-Inge Flakstad flakstad at npolar.no
Tue Oct 15 16:25:14 CEST 2013


Hi Àlex,

Silly question perhaps, but since it's not completely apparent from the code you provided: Are you missing something like

resp.getWriter().write(buffer.toString());

?

Just returning won't do much (and that fits with what you're experiencing).

Cheers,
Paul

From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Àlex Rodríguez Bacardit
Sent: 14. oktober 2013 17:56
To: opencms-dev at opencms.org
Subject: [opencms-dev] Download a file from administration point

Hi,

I'm trying to create a dialog to download a file for an administration point (à la CmsUsersCsvDownloadDialog) to download an html file with a certain content. The class extends CmsWidgetDialog

I've generated a method downloadFile() that redirects a StringBuffer to the response, that makes like this:

...
             StringBuffer buffer = new StringBuffer();

             HttpServletResponse resp = CmsFlexController.getController(getJsp().getRequest()).getTopResponse();

             resp.setContentType("text/html");
             buffer.append(exportFileContent);
             resp.setHeader("Content-Disposition", new StringBuffer("attachment; filename=\"").append(filename).append("\"").toString());
             resp.setContentLength(buffer.length());

             LOG.info("End actionCommit() method. Buffer content: " + buffer.toString());

             return buffer.toString();

The buffer.toString() method returns, of course, the correct value. That is, the content of the StringBuffer. However, I'm getting a blank .html file with no content inside. What could have possibly gone wrong?

Thanks in advance,
Àlex Rodríguez Bacardit<http://www.linkedin.com/in/alexrodba>
Consultor e-Business
alex.rodriguez at vass.es<mailto:alex.rodriguez at vass.es>
VASS Consultoría de Sistemas
Tel: +34 93 182 0963
Fax: +34 933 184 291
Avinguda Diagonal 210, 4a planta
08018 Barcelona
www.vass.es<http://www.vass.es/>
Este correo electrónico así como los documentos adjuntos contienen información confidencial y reservada. Si ha recibido este mensaje por error siga las instrucciones contenidas en nuestro Aviso Legal<http://vass.es/es/aviso-legal>. Si no deseara recibir más comunicaciones por correo electrónico comuníquelo en la siguiente dirección: general at vass.es<mailto:general at vass.es>
P Antes de imprimir este mensaje, asegúrese de que es necesario. El medio ambiente está en nuestra mano.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20131015/5fcbc64d/attachment.htm>


More information about the opencms-dev mailing list