[ERROR] [15:57:26.906 ExportServlet.java:135]  IO异常 :
org.mortbay.jetty.EofException
        at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:760)
        at org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:566)
        at org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:910)
        at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:646)
        at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:587)
        at org.apache.poi.poifs.storage.BigBlock.doWriteData(BigBlock.java:55)
        at org.apache.poi.poifs.storage.DocumentBlock.writeData(DocumentBlock.java:220)
        at org.apache.poi.poifs.storage.BigBlock.writeBlocks(BigBlock.java:86)
        at org.apache.poi.poifs.filesystem.POIFSDocument$BigBlockStore.writeBlocks(POIFSDocument.java:603)
        at org.apache.poi.poifs.filesystem.POIFSDocument.writeBlocks(POIFSDocument.java:275)
        at org.apache.poi.poifs.filesystem.POIFSFileSystem.writeFilesystem(POIFSFileSystem.java:390)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1168)
        at com.expayment.antiIntrusionSystem.ExportServlet.doGet(ExportServlet.java:130)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
        at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
        at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
        at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
        at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
Caused by: java.io.IOException: 远程主机强迫关闭了一个现有的连接。
        at sun.nio.ch.SocketDispatcher.writev0(Native Method)
        at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:37)
        at sun.nio.ch.IOUtil.write(IOUtil.java:164)
        at sun.nio.ch.SocketChannelImpl.write0(SocketChannelImpl.java:365)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:388)
        at java.nio.channels.SocketChannel.write(SocketChannel.java:360)
        at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:229)
        at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:197)
        at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:682)
        ... 36 more这个异常的操作是我在点击一个a标签,导出一个excel文件的时候,只要点击这个标签就会出现这个异常,请大家帮忙看看是什么原因,谢谢大家。
我知道EofException的异常但是不知道为什么会出现IOException异常继而导致了EofException,这个和jetty配置有关还是代码上面有不合理的地方,多谢大家帮助了。

解决方案 »

  1.   

    public class ExportServlet extends HttpServlet { public static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private final static Logger log = Logger.getLogger(ExportServlet.class.getName()); protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { String inputCalDateStr = request.getParameter("inputCalDate");
    String inputCalDate2Str = request.getParameter("inputCalDate2");
    String type = request.getParameter("type");
    String stateClass = request.getParameter("stateClass"); String s = "from TerminalEventRecords where 1=1 ";
    if (Utils.isBlank(inputCalDateStr)) {
    Date inputCalDate;
    try {
    inputCalDate = dateFormat.parse(inputCalDateStr);
    s += " and recordtime >= " + Utils.toOracleDateSql(inputCalDate);
    } catch (ParseException e) {
    log.error("开始日期格式异常!", e);
    }
    }
    if (Utils.isBlank(inputCalDate2Str)) {
    Date inputCalDate2;
    try {
    inputCalDate2 = dateFormat.parse(inputCalDate2Str);
    s += " and recordtime <= " + Utils.toOracleDateSql(inputCalDate2);
    } catch (ParseException e) {
    log.error("结束日期格式异常!", e);
    }
    }
    if (null != type && !type.equals("all") && !type.equals("")) {
    s += "and terminalType ='" + type + "'";
    } if (null != stateClass && !stateClass.equals("all") && !stateClass.equals("")) {
    s += "and stateClass ='" + stateClass + "'";
    } s += " order by recordtime desc"; log.info("导出excel文件的SQL : " + s);
    List events = HibernateUtil.listModel(s.toString());
    log.info("events.size() = " + events.size()); HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet1 = wb.createSheet("sheet1");
    HSSFRow row = sheet1.createRow(0);
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(new HSSFRichTextString("记录时间"));
    cell = row.createCell(1);
    cell.setCellValue(new HSSFRichTextString("终端类型"));
    cell = row.createCell(2);
    cell.setCellValue(new HSSFRichTextString("状态信息"));
    cell = row.createCell(3);
    cell.setCellValue(new HSSFRichTextString("事件"));
    cell = row.createCell(4);
    cell.setCellValue(new HSSFRichTextString("地址")); Terminal ter;
    for (int i = 0; i < events.size(); i++) {
    TerminalEventRecords event = (TerminalEventRecords) events.get(i);
    row = sheet1.createRow(i + 1);
    cell = row.createCell(0);
    cell.setCellValue(new HSSFRichTextString(dateFormat.format(event
    .getRecordtime())));
    cell = row.createCell(1);
    cell.setCellValue(new HSSFRichTextString(event.getTerminalTypeName()));
    cell = row.createCell(2);
    cell.setCellValue(new HSSFRichTextString(event.getTerminalStateClassName()));
    cell = row.createCell(3);
    cell.setCellValue(new HSSFRichTextString(event.getDescription()));
    cell = row.createCell(4);
    ter = SystemModel.getTerminalByTypeAndId(event.getTerminalType(), event
    .getTerminalId());
    if (ter == null)
    cell.setCellValue(new HSSFRichTextString("该节点已删除!"));
    else
    cell.setCellValue(new HSSFRichTextString(ter.getAddressName())); }
    for (short i = 0; i < 5; i++) {
    sheet1.autoSizeColumn(i);
    } response.setContentType("application/msexcel");
    response.addHeader("Content-Disposition", "attachment;filename="
    + new String("文件.xls".getBytes(), "iso-8859-1"));
    try {
    OutputStream out = response.getOutputStream();
    wb.write(out);
    out.close();
    } catch (FileNotFoundException e) {
    log.error("文件找不到异常 : ", e);
    } catch (IOException e) {
    log.error("IO异常 : ", e);
    }
    } protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    }}
      

  2.   

    我知道EofException这个异常,加内特,但是是什么引起的呢,我又该怎么修改代码呢。谢谢