1

For a web application built on struts and jsp technologies, I'm looking for a good example which explains how to download files from the server side.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
fatiDev
  • 5,752
  • 7
  • 28
  • 45

1 Answers1

1

i manage to do it with this few lines of code : just add this to your action :

OutputStream out = response.getOutputStream();
        response.setContentType("application/rtf");
        FileInputStream in = new FileInputStream("your_file_path");
        byte[] buffer = new byte[4096];
        int length;
        while ((length = in.read(buffer)) > 0){
            out.write(buffer, 0, length);
        }
        in.close();
        out.flush();
fatiDev
  • 5,752
  • 7
  • 28
  • 45
  • 1
    You'll also want to set the content disposition and filename, and return a `null` instead of an `ActionForward` so Struts knows the response was handled within the action. That sure is an old version of Struts. – Dave Newton Aug 24 '12 at 19:41
  • yeah , but for actionForward ,why it is not possible to call it ? because in my action i change data in the database and want to return my jsp to display the new data.... any way ? – fatiDev Aug 24 '12 at 19:44
  • I don't know what you're asking. – Dave Newton Aug 24 '12 at 19:46