Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7562463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:24:47+00:00 2026-05-30T13:24:47+00:00

Need help in figuring out, why the downloaded file size is 0 bytes? On

  • 0

Need help in figuring out, why the downloaded file size is 0 bytes? On click of the download button it the page pops up a save or open dialog box, when I choose save with some location is saves the file, but it is a empty file. Whats wrong with it?

JSP file

<form target="_blank" method="get" action="/csm/download.action" >
    <input type="hidden" id="absFileName" name="absFileName" value="">
    <input type="submit" class="btn" id="btnDownloadConfig" value="Download Configuration"/>
</form>

Struts.xml

<action name="download" class="com.abc.csm.actions.DownloadConfiguration">
    </action>

My code for download

String filePath = ServletActionContext.getServletContext().getRealPath("/")
filePath+=executionResponse

def splits=filePath.split("/")

cfgfileFileName=splits[splits.length-1]

println filePath+", "+cfgfile+", "+cfgfileFileName+", "+executionResponse

File f=new File(filePath)

println("Does file Exists? "+f.exists())

InputStream  inputStream = new FileInputStream(f)

response.setContentType("APPLICATION/xml")

response.addHeader("Content-Disposition", "attachment; filename=\""+cfgfileFileName+"\"")

My ouput in console

E:\Tomcat 6\webapps\csm\files//1123/Infa9_1_csmclientbeetle.xml, Infa9_1_csmclientbeetle.xml, files//1123/Infa9_1_csmclientbeetle.xml
Does file Exists? true

My file location in the tomcat webapps

E:\Tomcat 6\webapps\csm\files\1123

Update

I found a similar question that helped me

This is what i did with InputStream

FileInputStream ins = new FileInputStream(f)
    OutputStream out = response.getOutputStream()
    byte[] buf = new byte[1024]
    int len = 0
    while ((len = ins.read(buf)) >= 0)
    {
        out.write(buf, 0, len)
    }
    ins.close()
    out.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:24:48+00:00Added an answer on May 30, 2026 at 1:24 pm

    I believe you can use S2 build in Stream result type to handle your download functionality in more flexible way.All you need to define fileInputStream in your action class which will be used to download your content.

    you can set all other things in your configuration file dynamically.Here is a sample code

    public class DownloadAction extends ActionSupport{
    
        private InputStream fileInputStream;
    
        public InputStream getFileInputStream() {
            return fileInputStream;
        }
    
        public String execute() throws Exception {
            fileInputStream = new FileInputStream(new File("location of your file"));
            return SUCCESS;
        }
    }
    

    you can use stream result tin your struts.xml file

    <action name="download" class="com.abc.csm.actions.DownloadConfiguration">
        <result name="success" type="stream">
          <param name="contentType">application/octet-stream</param>
          <param name="inputName">fileInputStream</param>
          <param name="contentDisposition">attachment;filename="fileABC.txt"</param>
          <param name="bufferSize">1024</param>
        </result>
       </action>
    

    All the above param, inside your action tag can be set dynamically. all you need to define the properties in you action class and use them in the configuration.

    e.g if you want to set content-type dynamically create a property in your action class with its getters and setters and set the values of this property inside your execute/any other method.
    you need to use the dynamic property value in your struts.xml file like

     <action name="download" class="com.abc.csm.actions.DownloadConfiguration">
            <result name="success" type="stream">
              <param name="contentType">${contentType}</param>
              <param name="inputName">fileInputStream</param>
              <param name="contentDisposition">attachment;filename="fileABC.txt"</param>
              <param name="bufferSize">1024</param>
            </result>
           </action>
    

    for details about the various properties than can be set inside your stream result, see the official doc

    stream-result

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help figuring out the best, cross-browser compatible way to SAVE user input
I need help figuring out how to change out the view in my application.
I need help figuring out how to display the contents of an NSArray into
I need help figuring out how to create a cell like the one representing
I need help figuring out some regular expressions. I'm running the dig command and
I need help figuring out why I am getting a segmentation fault here. I
I need help on figuring out how to create a repository on github to
I need some help figuring out what I'm doing wrong here. I am trying
Need help figuring out how to do this. My code: my %hash; $hash{'1'}= {'Make'
I need help figuring out how to accomodate situations in which $hash {$i} is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.