0

我有一个 struts 动作,它有一个文档作为响应,这是代码:

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;
    }
}

我想通过 ajax id 调用此操作,如下所示:

$.ajax({
  type: "POST",
  url: "../generateBlame.do",
 });

我无法像使用表格那样下载文件

4

1 回答 1

1

您需要使用类似这个 jQuery 下载插件或等效的东西。

于 2012-09-04T15:42:47.250 回答