另存为DialogueBox在servlet response.setHeader中不起作用

我正在通过单击button将jqgrid中显示的数据导出到.excel文件中。 这里是我的代码导出到Excelbutton点击..

$('#excel').click(function(){ var fromdate=$('#fromdate').val(); var todate=$('#todate').val(); if(fromdate && todate) { var URL='excel?fromdate='+$('#fromdate').val()+'&todate='+$('#todate').val(); $.ajax({ url:URL, type:'GET', success:function(data){ alert('Exported To Excel'); } }); } }); 

现在这个button将直接指向excel.java页面,这是servlet.Below是我的exceljava页面代码。现在我需要Asper当用户点击导出到excelbutton时打开一个对话框并保存为对话框应该popup,使用户能够给予所需名称和保存到所需的位置,但它不会发生这种code.plz指出我的错误..

excel.java

  try { response.setHeader("Content-Type", "application/vnd.ms-excel"); response.setHeader("Content-Disposition","attachment; filename=excel.xls"); String datum1 = request.getParameter("fromdate"); String datum2 = request.getParameter("todate"); SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MM-yyyy"); Date date = sdfSource.parse(datum1); Date date2 = sdfSource.parse(datum2); SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd"); datum1 = sdfDestination.format(date); System.out.println(datum1); datum2 = sdfDestination.format(date2); System.out.println(datum2); HSSFWorkbook hwb = new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet("CallBillingSystem"); HSSFRow rowhead = sheet.createRow((short) 0); rowhead.createCell((short) 0).setCellValue("calldate"); rowhead.createCell((short) 1).setCellValue("src"); rowhead.createCell((short) 2).setCellValue("dst"); rowhead.createCell((short) 3).setCellValue("dstchannel"); rowhead.createCell((short) 4).setCellValue("lastapp"); rowhead.createCell((short) 5).setCellValue("duration"); rowhead.createCell((short) 6).setCellValue("disposition"); rowhead.createCell((short) 7).setCellValue("amaflags"); rowhead.createCell((short) 8).setCellValue("cdrcost"); String strQuery = ""; ResultSet rs = null; conexion conexiondb = new conexion(); conexiondb.Conectar(); strQuery = "SELECT * FROM cdrcost where date(calldate) between '" + datum1 + "' and '" + datum2 + "'"; //strQuery = "SELECT * FROM cdrcost where date(calldate) between '2011-09-01' and '2012-01-01'"; rs = conexiondb.Consulta(strQuery); int i = 1; while (rs.next()) { HSSFRow row = sheet.createRow((short) i); row.createCell((short) 0).setCellValue(rs.getString("calldate")); row.createCell((short) 1).setCellValue(rs.getString("src")); row.createCell((short) 2).setCellValue(rs.getString("dst")); row.createCell((short) 3).setCellValue(rs.getString("dstchannel")); row.createCell((short) 4).setCellValue(rs.getString("lastapp")); row.createCell((short) 5).setCellValue(rs.getString("duration")); row.createCell((short) 6).setCellValue(rs.getString("disposition")); row.createCell((short) 7).setCellValue(rs.getString("amaflags")); row.createCell((short) 8).setCellValue(rs.getString("cdrcost")); i++; } FileOutputStream fileOut = new FileOutputStream(filename); hwb.write(fileOut); hwb.write(response.getOutputStream()); System.out.println("Your excel file has been generated!"); FileOut.close(); } catch (Exception ex) { System.out.println(ex); } }