Why am I getting a NoClassDefFoundError on HttpServletRequest that is pointing to ServletFileUpload?

依然范特西╮ 提交于 2019-11-29 07:29:57

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 :)

This means that your servlet container does not have the servlet api. Take a clean installation of Tomcat and try to deploy there. First check that you have the servlet api jar in tomcat/lib. And make sure you don't have it in webapps/yourapp/WEB-INF/lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!