Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery ajax和servlet导出到excel_Jquery_Ajax_Excel_Servlets - Fatal编程技术网

使用jquery ajax和servlet导出到excel

使用jquery ajax和servlet导出到excel,jquery,ajax,excel,servlets,Jquery,Ajax,Excel,Servlets,我在编写将数据(来自服务器)导出到excel文件的代码时遇到问题。为此,我编写了简单的代码 ajax调用调用我的导出到excelservlet $.ajax({ url : "http://localhost:8800/project/abc/export", type: "POST", data : data, dataType: "text"

我在编写将数据(来自服务器)导出到excel文件的代码时遇到问题。为此,我编写了简单的代码

ajax调用调用我的导出到excelservlet

 $.ajax({
                url : "http://localhost:8800/project/abc/export", 
                type: "POST",
                data : data,          
                dataType: "text",
               /* contentType: "application/vnd.ms-excel",*/
                success : function(data, text_status, XMLHttpRequest) {
                    console.log("export done");         
                },
                error : function(XMLHttpRequest, text_status, error) {
                    console.log("error"+text_status+":::"+error);
                }
            });
下面是我的Servlet代码:

@Path("/abc")
public class Resource {


    @POST
    @Path("/export")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces("application/vnd.ms-excel")
    public Response exportResults(@Context HttpServletRequest req,@Context HttpServletResponse resp) {
        Workbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("results");
        Row header = sheet.createRow(0);
        header.createCell(0).setCellValue("tttttt");        
        File f =new File("new-excel-file.xls");     
        FileOutputStream fos;
        ResponseBuilder response = null ;
        try {
            fos = new FileOutputStream(f);
             wb.write(fos);  
             response= Response.ok((Object) f);

                fos.close(); 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           

        response.header("Content-Disposition",
                "attachment; filename=new-excel-file.xls");
         response.header("Content-Type","application/octet-stream"); 
        return response.build();
    }

}
我希望在ajax调用完成后出现一个弹出窗口,要求保存文件。我可以看到ajax调用后打印的数据,但没有弹出窗口。有人能帮我吗

我的ajax请求是POST请求,所以我不能使用window.location=url