i have a struts action that’s have a doc as response this is the code :
public class GenerateBlame extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println("it's ok!");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:\\Users\\free\\Desktop\\myworkspace\\gestionRH\\WebRoot\\fiches\\decisionRetraitSanction.doc"));
HWPFDocument doc = new HWPFDocument(fs);
Range r = doc.getRange();
r.replaceText("<dateDemande>", "test");
doc.write(new FileOutputStream("C:\\Users\\free\\Desktop\\myworkspace\\gestionRH\\WebRoot\\fiches\\decision.doc"));
OutputStream out = response.getOutputStream();
response.setContentType("application/rtf");
response.setHeader("Content-Disposition","attachment; filename=Decision");
FileInputStream in = new FileInputStream("C:\\Users\\free\\Desktop\\myworkspace\\gestionRH\\WebRoot\\fiches\\decision.doc");
byte[] buffer = new byte[4096];
int length;
/* while ((length = in.read(buffer)) > 0){
out.write(buffer, 0, length);
}
in.close();
out.flush();*/
return null;
}
}
i want to call this action via ajax id do like this :
$.ajax({
type: "POST",
url: "../generateBlame.do",
});
i can’t get the file downloeded as i’did whith a form
You need to use something like this jQuery download plugin or equivalent.