问题
I have a problem with my servlet engine i.e. Tomcat. I am using Windows-7 as my OS. I have installed my Tomcat into this folder C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0.
I have set my classpath to following:
C:>SET CLASSPATH="C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"
For running the servlet application i compiled my servlet program and generated the class file. I can easily compile my programs and get a class files.
But when i try to run the tomcat http://localhost:8080/ it gives me the status code 404 - File not Found..Why so??
Thanks..
回答1:
Setting the CLASSPATH is unnecessary, even undesirable. I don't have a CLASSPATH environment variable on any machine that I use. Tomcat knows where that servlet.jar is. Your app needs it in order to compile, but the right thing to do is to include that JAR using the -classpath command line option.
Is your servlet in a package? Tomcat doesn't allow servlets or classes that aren't in packages.
Did you package your servlet into a WAR file? That would be a good idea. Use the standard directory structure, put your servlet .class file in the WEB-INF/classes directory, create a web.xml file that describes your servlet, and package all of it into a WAR.
You should go through this carefully.
If you create a foo.war file, and put that in the Tomcat /webapps directory, you'll access it using this URL:
http://localhost:8080/foo/<servlet-name-here>
The HTTP 404 means that you didn't register your web app properly. The web server/Tomcat can't associate a resource with the URL you gave it.
回答2:
This post is not cohererent:
For running the servlet application i compiled my servlet program and generated the class file. I can easily compile my programs and get a class files.
You need to create a WAR
i.e. a web application with an associated web descriptor in order to deploy your servlets.
But when i try to run the tomcat http://localhost:8080/ it gives me the status code 404 - File not
Which file are you talking about? This is the url for Tomcat's web management interface
来源:https://stackoverflow.com/questions/9047544/servlet-tomcat-path