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

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:

Leave a Comment