java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

自闭症网瘾萝莉.ら 提交于 2019-11-26 20:47:02
BalusC

This can happen when you've placed server-specific libraries in the webapp's /WEB-INF/lib or probably JRE/lib. Big chance that you copied Tomcat's /lib/servlet-api.jar into there. You shouldn't do that. This would only lead to collisions in the classpath which leads to this kind of errors and it will make your webapp unportable (i.e. it is tied to run on Tomcat only, you can't run it at another servers like Glassfish, JBoss AS, Websphere, etc). You should keep the server-specific libraries at their default location. Cleanup the /WEB-INF/lib from any server-specific libraries and cleanup JRE/lib from any 3rd party libraries.

You probably copied server-specific libraries there because you wasn't able to compile your servlets. Copying the libraries in /WEB-INF/lib is the wrong solution. You should basically just specify those libraries in the compiletime classpath. Since you're using Eclipse, this can be done easily: first add Tomcat in Servers view, then associate your webapp project with the integrated Tomcat instance. This way Eclipse will automatically add the server-specific libraries to the project's buildpath. On a brand new web project you can choose the server during project creation wizard. On existing web projects, you can modify it in Targeted Runtimes section in project's properties.

See also:

You must have incorrectly copied commons-fileupload.jar to JRE/lib/ext, JRE/lib/endorsed, or otherwise placed it on a classpath that does not have visibility to the servlet APIs. Start the JVM with -verbose:class, which will print which classpath loaded the ServletFileUpload class. If the class is loaded from anywhere other than WEB-INF/lib, you'll need to remove it.

Remove any servlet-api.jar or the upload helping jar commons from JRE/lib or JRE/lib/ext. This helped me fix the problem.

Old thread but can still help someone. I saw that i had a javax-servlet jar in the dependency included with a test scope. I made it to provided scope. Check the dependency graph if you are using Eclipse +Maven.

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