Servlet-调用java函数

时间:2013-03-25 06:18:30

标签: java api function servlets import

我有一个包含函数的java文件。它使用一些外部API。(我添加了外部jar文件)。 现在我有一个servlet并在doGet()中想要调用上面java类的函数。 我是否必须在servlet中编写API的所有import语句?
因为我在servlet中运行时出错。

错误 HTTP状态500 - Servlet执行引发异常

type Exception report

message Servlet execution threw an exception

description The server encountered an internal error that prevented it from fulfilling     this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
hello.hello.doGet(hello.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause

java.lang.ClassNotFoundException: jxl.read.biff.BiffException
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
hello.hello.doGet(hello.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

3 个答案:

答案 0 :(得分:3)

我在Tomcat 7.0 \ lib中复制了外部JAR文件,它解决了这个问题。

http://scn.sap.com/thread/1410297

得到了这个想法

这是正确的解决方案吗? 那就是每当我们必须在servlet中使用外部API时,我们必须配置构建路径添加JAR并在tomcat \ lib文件夹中复制JAR吗?

答案 1 :(得分:0)

只需在具有该方法的servlet中导入该类。粘贴堆栈跟踪或一些有助于解决错误的代码。

答案 2 :(得分:0)

将jar文件复制到项目的WEB INF / lib文件夹中