问题描述
最近我开始使用JMeter来加载测试我的web应用程序,本地在我的电脑上。我有一个上传图片的jsp页面。图像由我的servlet处理。当我今天尝试这个过程时,我得到了下面的异常/错误: 异常
javax。 servlet.ServletException:Servlet执行抛出一个异常
根本原因
java.lang.NoClassDefFoundError:javax / servlet / http / HttpServletRequest
org.apache.commons。 fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)
spyder.servlets.imageProcessing.ImageProcessingServlet.uploadEditedImagesToDB(ImageProcessingServlet.java:527)
spyder.servlets.imageProcessing.ImageProcessingServlet.doPost(ImageProcessingServlet。 java:153)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
code
$ b $ p
$ b $ p
pre> boolean isPart = ServletFileUpload.isMultipartContent(req);
....而且,我已经把所有必要的 import类中的
语句。
我不记得对我的系统上的任何东西进行任何更改都会导致这个问题。这个过程总是没有任何问题,所以我不明白是什么原因导致它现在失败。它是相当巧合的,我认为,这是失败后,我已经使用JMeter ... ... $ / $>
所有第三方webapp像Commons FileUpload这样的库属于你的web应用程序的 / WEB-INF / lib
,而不是其他地方。每当你把它放在 JRE / lib
或 JRE / lib / ext
中时,就会发生这个异常。
事实上,正如Bozho提到的那样,您还需要确保您没有移动/复制/复制任何特定于servletcontainer的库(它们应该保留在 Tomcat / lib
)在classpath的不同位置。但是,国际海事组织不应该导致这种例外。这基本上是说,加载FileUpload API的类加载器完全不了解Servlet API。
I recently started using JMeter to load test my webapp, locally on my pc. I have a jsp page for uploading images. The images are processed by my servlet. When I tried the process today, I got the following exception/error :
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)
spyder.servlets.imageProcessing.ImageProcessingServlet.uploadEditedImagesToDB(ImageProcessingServlet.java:527)
spyder.servlets.imageProcessing.ImageProcessingServlet.doPost(ImageProcessingServlet.java:153)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Here is the code from my servlet that the exception is referring to -
boolean isPart = ServletFileUpload.isMultipartContent(req);
....and yes, I've put all the necessary import
statements in the class.
I can't recall making any changes to anything on my system that would cause this problem. This process has always run without any problems, so I don't understand what is causing it to fail like this now. Its rather coincidental, I think, that it is failing after I've been using JMeter...
All 3rd party webapp libraries like Commons FileUpload belong in /WEB-INF/lib
of your webapp, not elsewhere. This exception can occur whenever you've placed it in JRE/lib
or JRE/lib/ext
.
And indeed, as Bozho mentions, you need to ensure as well that you haven't moved/copied/duplicated any servletcontainer-specific libraries (which should be left untouched in Tomcat/lib
) around in different places of the classpath. But that should IMO not have resulted in this kind of exception. It's basically telling that the classloader which loaded the FileUpload API has totally no knowledge about the Servlet API.
If you read the Tomcat classloading HOW-TO, then you'll see that the libraries in JRE/lib
and JRE/lib/ext
are loaded by a different classloader (bootstrap) than the ones in Tomcat/lib
(common) and /WEB-INF/lib
(webapp). The bootstrap classloader has no knowledge about common and webapp libraries. It's the other way round. The common classloader has knowledge about the bootstrap classloader and the webapp classloader has knowledge about both. Since the Servlet API is normally loaded by the common classloader, this can only mean that the FileUpload API was loaded by the bootstrap classloader. And this is wrong :)
这篇关于为什么我得到一个指向ServletFileUpload的HttpServletRequest的NoClassDefFoundError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!