简体   繁体   中英

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream

I am getting this error with a simple tomcat jsp project. The articles I've read on google implies that I should include servlet-api.jar in my project. I did just that but it is not working. Does anyone have any ideas on this? I have sql-connector in my JRE and sql-connector.jar and cos.jar in my build path.

The articles I've read on google implies that I should include servlet-api.jar in my project. I did just that but it is not working

You should not do that. This is recipe for more trouble. See also How do I import the javax.servlet API in my Eclipse project? Remove those files from your project.

Coming back to your initial problem, I understand that you were already facing this problem before you attempted to solve it by including servlet container specific JAR files in your project.

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream

This kind of error will occur if you have included a JAR file which is in turn depending on the javax.servlet.ServletInputStream class in the wrong place in the classpath, there where the class loader is not aware about the classes which are loaded by the servlet container itself. For example, when you've included Apache Commons FileUpload JAR file in JRE's own JRE/lib or JRE/lib/ext folder instead of webapp's own /WEB-INF/lib folder. You should not put application-specific classes in the JRE library. Remove those files from the JRE library. This is a common beginner's mistake when they encountered a compilation error while using javac without the proper -cp / -classpath argument.

You must not include or deploy any servlet/JSP API jars in your project. Doing so leads to all manners of weirdness. Remove the libraries already supplied by Tomcat.

ServletInputStream is part of the servlet API. If you are running a version of tomcat that supports the version of the servlet API you are using, and if your tomcat installation is not corrupted, it will work. The servlet-api.jar should be located in TOMCAT/lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM