使用 Apache FileUpload 时出现 java.lang.NoClassDefFoundError
我正在使用 Apache FileUpload,并且收到 java.lang.NoClassDefFoundError
我的第一个想法是检查 .jar 是否在类路径上 - 我注意到(在 Eclipse 中)是在库区域下,有两个不同的部分:
- Apache Tomcat v6.0
- Web 应用程序库
所有其他库都列在“Web 应用程序库”下,并且此特定库列在 Apache Tomcat v6.0 下
我假设这导致了问题...我的代码在下面..但我认为这是一个配置问题而不是代码问题。
最后 - web.xml 不是问题,因为我已经从 servlet 中取出了 FileUpload 内容,并且发现 servlet 很好。
public class SaveImage extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println("Got here");
response.setContentType("text/html;charset=UTF-8");
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
}
I am using Apache FileUpload and I am getting a java.lang.NoClassDefFoundError
My first thought was to check whether the .jar was on the classpath - what I notice (in Eclipse) is that under the libraries area, there are two different sections:
- Apache Tomcat v6.0
- Web App Libraries
All the other libraries are listed under "Web App Libraries" and this particular library is listed under Apache Tomcat v6.0
I am assuming this is causing the problem ... my code is here below ... but I think it's a config issue rather than a code issue.
Finally - the web.xml is not the problem as I have taken out the FileUpload stuff from the servlet and the servlet gets found just fine.
public class SaveImage extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
System.out.println("Got here");
response.setContentType("text/html;charset=UTF-8");
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这必须是一个类路径问题。您的 IDE 认为的类路径上的内容并不像 Web 服务器认为的类路径上的内容那么重要。应用部署后(在部署目标目录中),
WEB-INF/lib
文件夹中有什么?这就是真正的类路径(当然还包括 Web 服务器的库)。This has to be a classpath issue. What your IDE thinks is on the classpath is not as important as what the web server thinks is on the classpath. What's in the
WEB-INF/lib
folder after your app is deployed (in the deployment target directory)? That's what the real classpath is (plus the web server's libs, of course).