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.
3 Answers
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.
-
I have followed the instructions in the article you provided but still getting the same error. I have also removed servlet-api.jar from my classpath. It is also not in JRE library. – user1195809 Feb 08 '12 at 13:33
-
1This particular issue can't be caused by having `servlet-api.jar` in JRE library, but a *different* JAR file such as for example `commons-fileupload.jar` or something which is depending on `javax.servlet.ServletInputStream`. In any way, you need to make absolutely sure that you have *not* changed the JRE (or Tomcat's) libraries after installing it. Uninstall and reinstall if you're unsure. – BalusC Feb 08 '12 at 13:39
-
This worked for me, once I found the dependency that was required. The advice is good, put the application jars into WEB-INF/libs and remove from the JRE classpath location. – Ed Neville Jan 23 '18 at 21:11
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.

- 158,873
- 26
- 254
- 302
-
-
@user1195809 Please edit your question to include the libraries you are deploying with your app. Have you modified your Tomcat or Java installation in any way? – Dave Newton Feb 08 '12 at 14:01
-
not Tomcat, I added sql-connector to JRE, but that shouldn't affect this. I have cos.jar and sql-connector.jar in the classpath. – user1195809 Feb 08 '12 at 15:23
-
@user1195809 Please edit your question to include the libraries you are deploying with your app. – Dave Newton Feb 08 '12 at 15:48
-
-
@user1195809 No, and until you provide additional information, no one will be able to help. – Dave Newton Feb 08 '12 at 19:12
-
but I did, I edited my question already. I reinstalled tomcat, there is no additional library under it. sql-connector and cos are in the buildpath. Do you have any ideas on what the problem might be? – user1195809 Feb 08 '12 at 19:20
-
@user1195809 Not without further information; I thought I said that. Try deploying *only* a JSP, *no* libraries. Note that it's completely irrelevant what your *build* path is, what matters is what's being deployed. – Dave Newton Feb 08 '12 at 19:26
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

- 588,226
- 146
- 1,060
- 1,140
-
-
Yes, that's precisely so. I even reinstalled tomcat, but still getting the same error. – user1195809 Feb 08 '12 at 19:26