如何处理错误java.io.IOException:处理JSP页面时发生异常?

时间:2015-10-28 03:15:58

标签: java jsp xls

我试图在JSP页面中读取excel文件。但是当我运行该程序时,我得到一个错误消息。你能告诉我处理这个错误的方法或者在JSP页面中读取excel文件的其他方法。

的index.jsp

<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@page import="org.apache.poi.ss.usermodel.Cell"%>
<%@page import="org.apache.poi.ss.usermodel.Row"%>
<%@page import="org.apache.poi.xssf.usermodel.XSSFRow"%>
<%@page import="org.apache.poi.xssf.usermodel.XSSFCell"%>
<%@page import="org.apache.poi.xssf.usermodel.XSSFSheet"%>
<%@page import="org.apache.poi.xssf.usermodel.XSSFWorkbook"%>
<%@page import="org.apache.poi.ss.usermodel.FormulaEvaluator"%>
<%@page import="java.io.*" %>
<%@page import="java.util.*" %>
<html>
<%
          FileInputStream fis = new FileInputStream(
          new File("C://excel//excel.xlsx"));
          XSSFWorkbook workbook = new XSSFWorkbook(fis);
          XSSFSheet sheet = workbook.getSheetAt(0);
          FormulaEvaluator formulaEvaluator=workbook.getCreationHelper().createFormulaEvaluator();
          for(Row row : sheet)
          {
              for(Cell cell : row)
              {
                  switch (formulaEvaluator.evaluateInCell(cell).getCellType()) 
                  {
                     case Cell.CELL_TYPE_NUMERIC:
                     System.out.println( 
                     cell.getNumericCellValue() + " \t\t " );
                     break;
                     case Cell.CELL_TYPE_STRING:
                     System.out.println(
                     cell.getStringCellValue() + " \t\t " );
                     break;
                  }
              }
          }

             System.out.println();
          fis.close();
          workbook.close();
    %>
    </html>

错误讯息:

  

HTTP状态500 - 处理JSP页面/index.jsp时发生异常   在第18行

     

输入例外报告

     

message在行处理JSP页面/index.jsp时发生异常   18

     

description服务器遇到阻止它的内部错误   完成此请求。

     

异常org.apache.jasper.JasperException:发生异常   在第18行处理JSP页面/index.jsp

     

15:&lt;%16:FileInputStream fis = new FileInputStream(17:
  新文件(&#34; C://excel//excel.xlsx")); 18:XSSFWorkbook工作簿=   新的XSSFWorkbook(fis); 19:XSSFSheet sheet =   workbook.getSheetAt(0); 20:FormulaEvaluator   formulaEvaluator = workbook.getCreationHelper()createFormulaEvaluator();   21:for(行行:表格)

     

堆栈跟踪:     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

     

根本原因javax.servlet.ServletException:   java.lang.NoClassDefFoundError:org / apache / xmlbeans / XmlException     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)     org.apache.jsp.index_jsp._jspService(index_jsp.java:170)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

     

root cause java.lang.NoClassDefFoundError:   组织/阿帕奇/的xmlbeans / XmlException     org.apache.jsp.index_jsp._jspService(index_jsp.java:132)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

     

root cause java.lang.ClassNotFoundException:   org.apache.xmlbeans.XmlException     org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)     org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)     org.apache.jsp.index_jsp._jspService(index_jsp.java:132)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

     

注意Apache中提供了根本原因的完整堆栈跟踪   Tomcat / 8。0。26日志。

0 个答案:

没有答案