gpt4 book ai didi

java - 从jsp调用java方法

转载 作者:行者123 更新时间:2023-12-01 16:57:32 26 4
gpt4 key购买 nike

我正在从 jsp 调用我的 java 方法,它给出 NoClassDefFoundError: error

但是当我从 main 方法调用时,我的方法正在工作。 我在代码中使用了 xlrd jar,并且还放置了 jar lib 文件夹。但仍然给出错误。

异常跟踪:

org.apache.jasper.JasperException: An exception occurred processing JSP page /exportDSD.jsp at line 20

17: //excel.getExcel();
18:
19: Report r = new Report();
20: r.generateReport();
21:
22: System.out.println("Generated DSD");
23: %>

堆栈跟踪:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
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:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因:

javax.servlet.ServletException: java.lang.NoClassDefFoundError: xlrd/Workbook
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.exportDSD_jsp._jspService(exportDSD_jsp.java:107)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
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:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

我的代码:

import org.apache.poi.hssf.usermodel.HSSFCell; 
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import xlrd.*;

public void generateReport() throws BiffException, ClassNotFoundException, SQLException, IOException {
... ...
}

从 jsp 我这样调用:

<% Report r =new Report(); r.generateReport(); %>

最佳答案

出现 JSP 导入不正确:

Add jar in WEB-INF/lib
Add <%@ page import="xlrd.*" %> to the top of your JSP

要导入多个类,请使用以下格式:

<%@ page import="com.sample.Report,xlrd.*" %>

关于java - 从jsp调用java方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30588932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com