struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Joshua" <daniel.jos...@gridnode.com>
Subject RE: upload files
Date Tue, 30 Jul 2002 02:24:45 GMT
Hi,

Sort of off-topic, anyway this is the not so elegant approach that I used...

      response.setContentType(CONTENT_TYPE);
      response.setHeader("Content-Disposition", "attachment; filename=\"" +
filename + "\"");
      ServletOutputStream out = response.getOutputStream();

      byte[] inBytes = new byte[DEFAULT_BUFFER_SIZE];
      FileInputStream fileInputstream = new FileInputStream(file);
      int len = fileInputstream.read(inBytes);
      while(len != -1) // Check for EOF
      {
        out.write(inBytes, 0, len);
        len = fileInputstream.read(inBytes);
      }

This should give you a pop up message box asking to Save, Open, etc. Instead
of 'attachment' you can also use 'inline'.


Regards,
Daniel

-----Original Message-----
From: Christian Pich [mailto:pich@llauwl.com]
Sent: Tuesday, July 30, 2002 4:26 AM
To: Struts Users Mailing List
Subject: Re: upload files


Well, I did that before without the struts framework and ran into problems:
I am working in frames so when I try to output specific contents then
it always defaults the contents to the frame source file contents. Also,
it would not allow me to set the default file name correctly.

Can I do it from an action class?


Bichiko, Dmitri wrote:

>you can set the content type from within the JSP page:
>
>response.setContentType("application/vnd.ms-excel")
>
>for the file name:
>
>response.setHeader("Content-Disposition","attachment;
filename=myfile.xls;")
>
>Dmitri
>
>-----Original Message-----
>From: Christian Pich [mailto:pich@llauwl.com]
>Sent: Monday, July 29, 2002 3:54 PM
>To: struts-user@jakarta.apache.org
>Subject: upload files
>
>
>How does struts envision to send files (images, documents) to the web
>user back?
>I could not find documentation about it? Is that done in the Action class?
>How do I set the contents-type, such as image/gif or others
>and how do I set the default name that appears for the user when he is
>asked to
>save the file on his disk?
>
>
>--
>To unsubscribe, e-mail:
><mailto:struts-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail:
><mailto:struts-user-help@jakarta.apache.org>
>
>--
>To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message