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

  • SEARCH
  • Home
  • 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 8113153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:44:13+00:00 2026-06-06T02:44:13+00:00

In my struts application, a user can download a file from the server. I

  • 0

In my struts application, a user can download a file from the server.

I want to show a spinner during the time between the button click (to initiate the download) and file is ready to download. Is there an event which is triggered when the file starts to download? I assume it would be some sort of page load event.

This is the section from my struts xml:

<action name="getFile" method="getFile" class="foo.pack.TAction">
    <result name="success" type="stream">
        <param name="contentType">application/pdf</param>
        <param name="contentDisposition">attachment;filename=${fileName}</param>
    </result>
    <result name="login" type="redirect">/login</result>
    <result name="error" type="tiles">showError</result>
</action>

On button click, I set window.location = localhost:8080/getFile.action
The file is downloaded next (after n seconds)

What would be a way to show the spinner during the time for which the file is being fetched from the server?

  • 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-06-06T02:44:15+00:00Added an answer on June 6, 2026 at 2:44 am

    For this answer, I’ll assume “plain” JSP/Servlet/HTML/JS as I don’t use Struts. For an advanced Struts (and jQuery) user it should however be trivial enough to port it to Struts (and jQuery).

    To the point, you could set a cookie on the response of the download request and have JavaScript to poll for that cookie. Once the download is ready to be served, the cookie will be available in JavaScript. To ensure working across various browser windows/tabs in the same session, best is to generate an unique download token and pass it back as request parameter so that the server side can set it as a cookie value. Don’t forget to expire the cookie afterwards to prevent cookie pollution.

    Basically (you could substitute the <span> with an <img> pointing to some spinner gif):

    <input type="button" value="Download" onclick="download()" />
    <span id="wait" style="display:none">Please wait while we prepare the download...</span>
    

    With this JavaScript (when using jQuery, the jquery-cookie plugin may be helpful):

    function download() {
        var token = new Date().getTime();
        var wait = document.getElementById("wait");
        wait.style.display = "block";
    
        var pollDownload = setInterval(function() {
            if (document.cookie.indexOf("download=" + token) > -1) {
                document.cookie = "download=" + token + "; expires=" + new Date(0).toGMTString() + "; path=/";
                wait.style.display = "none";
                clearInterval(pollDownload);
            }
        }, 500);
    
        window.location = "download?token=" + token;
    }
    

    And in the servlet (or Struts action if applicable):

    // Prepare download here.
    // ...
    
    // Once finished, set cookie and stream download to response.
    Cookie cookie = new Cookie("download", request.getParameter("token"));
    cookie.setPath("/");
    response.addCookie(cookie);
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a struts 2 web application where user can upload file
When a user signs up in our Struts application, we want to send them
I have to tell to the user in a web application(using struts) the download
I am building a struts 2 application with JPA. A user can login into
I have a struts application that has a form to edit user details. I
In my strut2 base web application . I want to create XLS file when
We have a web application where users can login. Now what we want is
I want to develop a Java EE application with a rich user interface which
I have a legacy Struts 1.2.8 application that I'm maintaining and porting from Oracle
How can I prevent a user from neglecting the normal work flow of a

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.