开发者社区> 问答> 正文

用jsp调用出现无法执行new XSSFWorkbook的情况,也无报错,请问问?报错

poi读取xlsx格式的程序单独运行正确 用jsp调用出现无法执行new XSSFWorkbook的情况,也无报错

public class Forexecute extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        XSSFWorkbook  rwb = null;
        MultipartFormDataRequest mrequest = null;
        try{            
            rwb = new XSSFWorkbook(new BufferedInputStream(new FileInputStream(new File("D:\\qzworkspace\\1.xlsx"))));
            // 读取第一章表格内容 
            XSSFSheet sheet = rwb.getSheetAt(0); 
            // 定义 row、cell 
            XSSFRow row; 
            String cell; 
            // 循环输出表格中的内容 
            for (int i = sheet.getFirstRowNum()+1; i < sheet.getPhysicalNumberOfRows(); i++) { 
                row = sheet.getRow(i); 
                for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) { 
                    // 通过 row.getCell(j).toString() 获取单元格内容, 
                    cell = row.getCell(j).toString(); 
                    System.out.print(cell + "\t"); 
                } 
                System.out.println(""); 
            }
            }catch(Exception e) {
                System.out.println("已运行xlRead() : " + e );
            }

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

    public static void main(String args[]) throws ServletException, IOException
    {
        Forexecute er = new Forexecute();
        HttpServletRequest request = null;
        HttpServletResponse response=null;
        er.doGet(request, response);
    }
}

上面是我java部分的程序,单独执行main函数调用poi读取excel没有问题,但是用jsp调用这个方法就会在执行new XSSFWorkbook()处停止,也无任何报错,求大神们帮帮忙看一下。

展开
收起
爱吃鱼的程序员 2020-06-23 01:00:28 771 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    控制台程序可以很大可能是你通过buildpath去引用的poi相关的jar,普通web项目需要把jar放在WEB-INF/lib这个文件夹里,否则在tomcat中运行时找不到对应的jar,当然如果是maven项目只要对应dependence引用就可以。

    2020-06-23 01:00:44
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载