나는 다음과 같은 상황이 :최근에 생성 된 파일을 다운로드 할 수 없습니다
$("#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);
});
});
서버 프로세스이 : 난, 사용자 에이전트가이 방법으로 아약스를 통해 서버로 데이터를 전송 동적으로 파일을 생성해야 을 파일 dynamicaly 만드는 작업과 데이터 : http://johnculviner.com/category/jQuery-File-Download.aspx
내가 얻을 :
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");
}
}
나는 다운로드를 할 수있는이 플러그인을 사용 n 오류 다운로드! . 내가 이미 존재하는 파일을 얻을, 또는이 코드에 약간의 시간 후 다운로드 트리거 할 때하지 않는 :
function timeout_trigger() {
fileName에 = $ ("# 테스트") ("입력")를 찾을 발.();
......}).done(function(data) {
setTimeout("timeout_trigger()",7000);
});
이 두 번째 솔루션은 항상 작동하지 않는, 그래서 내가이 문제를 해결해야합니다 }
는 느릅 나무 나는이 방법을 사용합니다. 왜 기존 파일이 문제없이 다운로드되고 최근에 다운로드시 오류가 표시됩니까?
파일 생성을위한 http 요청이 완료되었지만 서버가 실제로 파일 생성을 완료하지 않은 타이밍 문제인 것으로 보입니다. 서버 측 코드에서 요청을 종료하고 다른 스레드에서 파일을 처리하고 있습니까, 아니면 요청이 끝나기 전에 완료해야합니까? –
일반적으로 파일을 다운로드하기 위해 클라이언트에 파일 이름을 반환하기 때문에 요청이 완료되기 전에 완료해야합니다. – fatiDev