小编典典

在JSP上使用Apache POI时发生异常

jsp

我正在尝试实现Apache POI,以将Excel文件中的数据显示为网页上的某些输入。我收到此异常:

exception 
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:677)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause 
java.lang.IllegalArgumentException: Page directive: invalid value for import
org.apache.jasper.compiler.Node$PageDirective.validateImport(Node.java:628)
org.apache.jasper.compiler.Node$PageDirective.addImport(Node.java:611)
org.apache.jasper.compiler.Parser.parsePageDirective(Parser.java:352)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:473)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1773)
org.apache.jasper.compiler.Parser.parse(Parser.java:135)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这是我的.jsp文件中的代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ page import="java.io.FileInputStream, 
java.io.FileNotFoundException, 
java.io.IOException, 
org.apache.poi.hssf.usermodel.HSSFCell, 
org.apache.poi.hssf.usermodel.HSSFRow,
org.apache.poi.hssf.usermodel.HSSFSheet,
org.apache.poi.hssf.usermodel.HSSFWorkbook;"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<body>

<% 
     HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("excel.xls"));
     HSSFSheet sheet = workbook.getSheetAt(0);
     HSSFRow row = sheet.getRow(1);
     double Something,Something1,Something2,Something3,Something4;

        Something= row.getCell(0).getNumericCellValue();
        Something1= row.getCell(1).getNumericCellValue();
        Something2= row.getCell(2).getNumericCellValue();
        Something3= row.getCell(3).getNumericCellValue();
        Something4= row.getCell(4).getNumericCellValue();

 %>

<div>
    <table>
        <tr>
            <td>Something: </td>
            <td><input type="text" value="<% Something %>"></td>
        </tr>
        <tr>
            <td>Something1: </td>
            <td><input type="text" value="<% Something1 %>"></td>
        </tr>
        <tr>
            <td>Something2: </td>
            <td><input type="text" value="<% Something2 %>"></td>
        </tr>
        <tr>
            <td>Something3: </td>
            <td>    <input type="text" value="<% Something3 %>"></td>
        </tr>
        <tr>
            <td>Something4: </td>
            <td><input type="text" value="<% Something4 %>"></td>
        </tr>
    </table>
</div>
</body>
</html>

有人知道哪里出问题了吗?


阅读 272

收藏
2020-06-10

共1个答案

小编典典

不知道您正在使用哪个服务器。但是,如果它是Tomcat
7.0.57或更高版本(也请参见此链接),则需要在import指令末尾删除分号(;)。尝试删除它,它应该可以工作。

2020-06-10