开发者

Tomcat servlet problem - class not found

开发者 https://www.devze.com 2022-12-10 16:23 出处:网络
I\'m trying to learn how to develop a servlet to run under Apache\'s Tomcat server on Windows XP. I\'m using Tomcat 6.0 with Java SDK 1.6.0_17. My webapp is a simple Hello, world type which I\'m build

I'm trying to learn how to develop a servlet to run under Apache's Tomcat server on Windows XP. I'm using Tomcat 6.0 with Java SDK 1.6.0_17. My webapp is a simple Hello, world type which I'm building using the latest version of the Eclipse IDE. I'm able to run all the examples in the Tomcat installation but when I export my app from Eclipse to the Tomcat webapps folder开发者_运维百科 and try to access it from my browser, I get errors pointing to the fact that the javax.servlet.http.Servlet class couldn't be found. I searched the SDK tree and couldn't find any thing with javax in the name so I'm guessing it isn't there.

I've googled around but haven't found anything with this exact, same issue. Any suggestions what I can try?


the Servlet class in servlet.jar, which is part of Java EE (the "Enterprise" part of Java) and not the regular JDK distribution. It's usually in Tomcat's classpath so once you get your app deployed to Tomcat there's little trouble finding it.

Usually, the problem with this jar is that it's not normally in Eclipse's classpath, so you end up with compile-time problems.

If it's really missing at runtime on Tomcat, try digging for it in your project's library dependencies (I can never figure out where Eclipse hides that stuff) and copy it into the "common/lib" subdirectory of your Tomcat installation.


It should be available in servlet-api.jar in Tomcat's own classpath, i.e. the Tomcat/lib folder.

If you get this particular error, there's probably more at matter. You maybe duplicated one or more of Tomcat's own libraries (one of the files in Tomcat/lib) into Eclipse or, more worse, the JDK/lib. You shouldn't do that. Keep all default libraries there where they belongs. Never duplicate/move them around. Only reference them.

If you want to develop webapps using Eclipse, you should have got at least the Eclipse for Java EE Developers and integrated Tomcat in Eclipse through the Servers view and have created a Dynamic Web Project wherein you have selected the afore-integrated Tomcat instance as the default server instance.

For more hints about using Eclipse and Tomcat together, you may find this tutorial useful (you may fully skip and ignore the JSF part if that is not of interest).

Edit: I realized that javax.servlet.http.Servlet class actually doesn't exist. You need either javax.servlet.Servlet or javax.servlet.http.HttpServlet. But that would already have failed during compiletime, not during runtime, so your problem was maybe not described very accurate.

0

精彩评论

暂无评论...
验证码 换一张
取 消