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 6362563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:55:29+00:00 2026-05-24T23:55:29+00:00

I have a Java project which is used as a component in a webapp.

  • 0

I have a Java project which is used as a component in a webapp. This java code writes an xls file in a specific folder. I want to provide a download functionality for this file which should be triggered as soon as file writing is done.
The problem is – without a server environment, how can write a download functionality?

  • 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-24T23:55:30+00:00Added an answer on May 24, 2026 at 11:55 pm

    Don’t write to file in a specific folder. Just write to the HTTP response body immediately. The downloading job should just be done in the webapp’s code. I assume that you’re using Servlets. If you set the HTTP response Content-Disposition header to attachment, then the browser will pop a Save as dialogue. If you also set the Content-Type header, then the browser will understand what to do with it (e.g. it will then be able to ask Do you want to open it in Excel or to save? and so on).

    response.setHeader("Content-Type", "application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
    
    // Now write xls to response.getOutputStream() instead of FileOutputStream.
    

    If the API of that Java project is well designed, then you should have a method something like this:

    public void writeXls(OutputStream output) throws IOException {
        // Do your job to write xls to output. E.g. if you were using POI HSSF:
        // WritableWorkbook workBook = Workbook.createWorkbook(output);
        // ...
    }
    

    This way you can call it in the servlet as follows after setting the aforementioned headers:

    yourClass.writeXls(response.getOutputStream());
    

    Even more, it could easily be reused/tested in a plain vanilla Java application like follows:

    yourClass.writeXls(new FileOutputStream("/path/to/foo.xls"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a java ee project which has a text file that uses a
I am considering starting a project which is used to generate code in Java
I have a JSP file which I am deploying within a Java Project with
I have a java project in which I have Referenced Libraries. In the Referenced
I have to give a general note to some huge Java project for which
I have developed some reusable android component which is basically a class . This
i have created a java application which uses data from its config folder and
I have Java project built with Maven2. There is used JUnit framework for testing
I have a project which will be made up mostly of Java Servlets, JSP/Html
I have a war packaging Maven project, in which I have a Java properties

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.