日期:2014-05-16 浏览次数:20375 次
//获取需要导出问卷答案的列表 function exportQuery() { var eCompanyId = $('eCompanyId').value; var eQuestionpaperId = $('eQuestionpaperId').value; var eTaskName = $('eTaskName').value; var eQuestionStartime = $('eQuestionStartime').value; var eQuestionEndtime = $('eQuestionEndtime').value; var url ='<%=basePath%>wjStatistic.do?method=AllExportWj&companyId='+eCompanyId+'&questionpaperId='+eQuestionpaperId+'&taskName='+eTaskName+'&questionStartime='+eQuestionStartime+'&questionEndtime='+eQuestionEndtime; url = encodeURI(encodeURI(url)); var checkName = new Request({ url:url, method:'post', onSuccess:function(text, xml){ var obj=eval("("+text+")");//转换为json对象 if(obj.msg=='1'){ //当msg为1表示查询结果又数据 var exportList = obj.exportList; for(var i = 0;i<exportList.length;i++) { var exportWj = exportList[i]; //alert(exportList.length); //exportOneWj(exportWj.questionpaper_id,exportWj.customer_questions_id); var exportURL = '<%=basePath%>/wjStatistic.do?method=OneExportWj&wjId='+exportWj.questionpaper_id+'&customQuestionId='+exportWj.customer_questions_id; //alert(exportURL); window.open(exportURL); //实现下载 } closeMsg(); return false; }else{ alert("本条件下无数据!"); } } }).send(); //$('exportSearchForm').submit(); }
public ActionForward OneExportWj(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { ServletOutputStream os = null; try { os = response.getOutputStream(); response.setContentType("text/xml;charset=UTF-8"); String wjId = URLDecoder.decode(request.getParameter("wjId"), "UTF-8"); String customQuestionId = URLDecoder.decode(request.getParameter("customQuestionId"), "UTF-8"); Map map=new HashMap(); map.put("wjId", wjId); map.put("customQuestionId", customQuestionId); String wjJo=wjStatisticService.getAnsweredWj(map); SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time= sm.format(new Date()); JSONObject jo=JSONObject.fromObject(wjJo); String filepath =jo.getString("title")+"_"+time+".html"; //问卷名+当前时间生成保存文件名称 // 设置HTTP头: response.reset(); response.setContentType("application/octet-stream"); String fileName = URLDecoder.decode(filepath, "utf-8"); respons