日期:2014-05-20 浏览次数:20903 次
2011-1-22 15:18:23 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet action threw exception java.lang.IllegalStateException: Cannot forward after response has been committed at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:312) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302) at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085) at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at loginfilter.LoginFilter.doFilter(LoginFilter.java:55) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619)
<form action="/NMSoftware/admission.do?method=queryExcel" method="post"> <input type="hidden" value="20" name="pagesize" /> <input type="hidden" value="1" name="pagenow" /> <input type="submit" value="导出Excel" /> </form>
public ActionForward queryExcel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ try { HttpSession session = request.getSession(); String spagenow = request.getParameter("pagenow"); String spagesize = request.getParameter("pagesize"); int pagenow = Integer.parseInt(spagenow); int pagesize = Integer.parseInt(spagesize); SqlBean sq = new SqlBean(); List list = null; String tt = ""; if (session.getAttribute("stockgoods") != null) { List sessionList = (List) session.getAttribute("stockgoods"); for (int i = 0; i < sessionList.size(); i++) { AddQueryForm af = (AddQueryForm) sessionList.get(i); tt += af.getFieldnamel() + " " + af.getOperator() + " '" + af.getFieldvalues() + "' " + af.getManner() + " "; } list = sq.accnsQuery(pagesize, pagenow, tt); } else { list = sq.accnsQuery(pagesize, pagenow, null); } String str = "学生登记信息表"; String sstr = new String(str.getBytes("gb2312"), "ISO-8859-1"); OutputStream os = response.getOutputStream();// 取得输出流 response.reset();// 清空输出流 response.setHeader("Content-disposition", "attachment; filename=" + sstr + ".xls");// 设定输出文件头 response.setContentType("application/msexcel");// 定义输出类型 response.setCharacterEncoding("gb2312"); WritableWorkbook wbook = Workbook.createWorkbook(os); // 建立excel文件 WritableSheet wsheet = wbook.createSheet("sheet1", 0); // sheet名称 // 设置excel标题 WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE); WritableCellFormat wcfFC = new WritableCellFormat(wfont); wcfFC.setAlignment(Alignment.CENTRE); // 开始生成主体内容 wsheet.addCell(new Label(0, 0, "编号")); wsheet.addCell(new Label(1, 0, "姓名")); wsheet.addCell(new Label(2, 0, "拼音码")); wsheet.addCell(new Label(3, 0, "性别")); wsheet.addCell(new Label(4, 0, "申请日期")); wsheet.addCell(new Label(5, 0, "入托方式")); wsheet.addCell(new Label(6, 0, "班级")); wsheet.addCell(new Label(7, 0, "接送方式")); wsheet.addCell(new Label(8, 0, "特长班")); int i = 1, j = 1; for (int n = 0; n < list.size(); n++) { Adms_Car_Class_Nur_SpeForm ssf = (Adms_Car_Class_Nur_SpeForm) list .get(n); wsheet.addCell(new Label(0, i, j + "")); wsheet.addCell(new Label(1, i, ssf.getAdname())); wsheet.addCell(new Label(2, i, ssf.getAdcode())); wsheet.addCell(new Label(3, i, ssf.getAdsex())); wsheet.addCell(new Label(4, i, ssf.getAdtime())); wsheet.addCell(new Label(5, i, ssf.getNursery())); wsheet.addCell(new Label(6, i, ssf.getClassname())); wsheet.addCell(new Label(7, i, ssf.getCarname())); wsheet.addCell(new Label(8, i, ssf.getSpecialtyname())); i++; j++; } // 主体内容生成结束 wbook.write(); // 写入文件 wbook.close(); os.flush(); os.close(); // 关闭流 } catch (Exception ex) { ex.printStackTrace(); } return mapping.getInputForward(); }