浏览 2546 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-09-22
<html:link page="/excel.do?action=byteacher&teacherid=1">生成EXCEL报表</html:link> 方式做的,服务器端的代码如下: public class ExcelAction extends BaseAction { public ActionForward doExcuteAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String actionType = request.getParameter("action"); if ("byteacher".equals(actionType.trim())) { String teacherId = request.getParameter("teacherid"); //利用业务组件从后端获取数据 List teacherSelectedAssignments = this.adminBussiness .getTeacherAssignment(Integer.parseInt(teacherId)); try { response.setContentType("application/vnd.ms-excel"); //利用ExcelReportUtil工具类生成excel文件 ExcelReportUtil.writeAssignmentExcelByTeacher( teacherSelectedAssignments, response.getOutputStream()); } catch (WriteException e) { // TODO Auto-generated catch block System.out.println("WriteException 错误"); } catch (IOException e) { System.out.println("IO 错误"); } } return null; } } 这样作是没有问题的,可以生长excel报表! 后来我想改为用ajax来作:关键代码如下: <script language="JavaScript"> HTTPRequest=function() { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (http_request) { return http_request; } } function getreportbyteacher(oSel){ alert(oSel.options[oSel.selectedIndex].value); var http = new HTTPRequest(); http.open("GET","/ecjtuthesis/excel.do?action=byteacher&teacherid="+oSel.options[oSel.selectedIndex].value,true); http.send(); } </script> …… <select name="assignTeacherId" id="teacher"> <c:forEach var="i" items="${teachers}"> <option value="${i.teacherId}"> <c:out value="${i.teacherName}" /> </option> </c:forEach> </select> 老师 <input type="button" value="生成报表" onclick="getreportbyteacher(document.all('teacher'));" /> ………… 调试发现: http.open("GET","/ecjtuthesis/excel.do?action=byteacher&teacherid="+oSel.options[oSel.selectedIndex].value,true); http.send(); 信息发送到了服务器端,没有问题,就是不见生成的excel文件!各位有没有碰到类似的问题,帮我分析一下,谢谢 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |