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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:51+00:00 2026-06-11T09:36:51+00:00

i have the following situation : i have to create files dynamically , the

  • 0

i have the following situation :
i have to create files dynamically , the user agent send data to the server via ajax in this way :

$("#generateButton").live("click",function(){
dateLimite = $("#dateLimite").val();
 $.ajax({
   type    : "POST",
   url     : "../generateFile.do",
   data    : { fileName: "demandeExplication",
   nbrParam: "3",
   param1:"<%=agent.getPrenomAgentArabe()+" "+agent.getNomAgentArabe()%>",
   param2:"<%=descriptionActe%>",
   param3:dateLimite,
   },
   dataType: "html",

}).done(function(data) {
$("#test").empty().append(data);
  fileName = $("#test").find("input").val();
$.fileDownload('http://localhost:8080/gestionRH/fiches/temp/'+fileName);

});
});

the server process this data with an action that create a file dynamicaly :

public class GenerateFile extends Action
{ 



public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws IOException {
    String fileName = request.getParameter("fileName");
    Integer nbrParam = Integer.parseInt(request.getParameter("nbrParam"));
    String[] valueParam = new String[nbrParam+1];
    for(int i =1;i<=nbrParam;i++)
    {  System.out.println(request.getParameter("param"+i));
        valueParam[i]=request.getParameter("param"+i);
    }
    FileInputStream in = new FileInputStream("C:\\Users\\free\\Desktop\\myworkspace\\gestionRH\\WebRoot\\fiches\\"+fileName+".doc");
    POIFSFileSystem fs = new POIFSFileSystem(in);
    HWPFDocument doc = new HWPFDocument(fs);
    Range r = doc.getRange();
    for(int i=1;i<=nbrParam;i++)
    {   System.out.println("<param"+i+">");
        System.out.println(valueParam[i]);
        r.replaceText("<param"+i+">", valueParam[i]);
    }


    File frr = new File("C:\\Users\\free\\Desktop\\myworkspace\\gestionRH\\WebRoot\\fiches\\temp");
    File temp = File.createTempFile("monfile",".doc",frr);
    FileOutputStream out = new FileOutputStream(temp);
    doc.write(out);
    out.close();
    in.close();
    request.setAttribute("fileName", temp.getName());
    return mapping.findForward("fileName");
}
}

i use a this plugin to do the download : http://johnculviner.com/category/jQuery-File-Download.aspx

i get an error download !
which i don’t get with already existing files , or when i trigger the download after some time with this code :

function timeout_trigger() {    

fileName = $(“#test”).find(“input”).val();
}

wich i use it in this way :

......}).done(function(data) {
setTimeout("timeout_trigger()",7000);
});

and this second solution is not always working , so i must solve this problem.
why already existing files are downloaded with no problems and recently created show errors on download ?

  • 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-11T09:36:53+00:00Added an answer on June 11, 2026 at 9:36 am

    That’s probably because the file hasn’t been uploaded, yet. With AJAX, the file is uploaded in the background. That takes time. The server code is triggered only after the whole file has been uploaded (it wouldn’t want to operate on a partial file).

    So what you need is a way to ask “Is there an upload for this in progress?”. When I had the same problem, I sent several AJAX requests. The first one would create a status object in the session where I would record the file name.

    When querying for the file, I’d look at that status object to see whether the upload was complete and return the status.

    There are also ways to hook into the upload process; when you do that, you can even add a “percentage uploaded” to the status object.

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

Sidebar

Related Questions

I have following Situation, Server A sends some data (HTML form) to server B,
I have following situation - Have a MongoService class, which reads host, port, database
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11
I have following situation: String a = A Web crawler is a computer program
I have the following situation: vec1 <- c(A, B, D, C, E, A, C)
I have the following situation: function Mach3Code(Str: String): String; var StrOut: String; begin StrOut
I have the following situation. We want an reputation table to evaluate Users And
I have the following situation: An Conversations entity/table which has multiple Tags associated to

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.