Servlet - Tomcat 路径
我的 servlet 引擎(即 Tomcat)有问题。我使用 Windows-7 作为我的操作系统。我已将 Tomcat 安装到此文件夹 C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0 中。
我已将类路径设置为以下内容:
C:>SET CLASSPATH="C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"
为了运行 servlet 应用程序,我编译了我的 servlet 程序并生成了类文件。我可以轻松编译我的程序并获得类文件。
但是当我尝试运行 tomcat http://localhost:8080/ 时,它给了我状态代码 404 - File not发现了..为什么会这样?
谢谢..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置 CLASSPATH 是不必要的,甚至是不可取的。我使用的任何计算机上都没有 CLASSPATH 环境变量。 Tomcat 知道 servlet.jar 在哪里。您的应用程序需要它才能编译,但正确的做法是使用 -classpath 命令行选项包含该 JAR。
你的 servlet 是在一个包中吗? Tomcat 不允许使用不在包中的 Servlet 或类。
您是否将 servlet 打包成 WAR 文件?那是个好主意。使用标准目录结构,将 servlet .class 文件放在 WEB-INF/classes 目录中,创建一个描述 servlet 的 web.xml 文件,并将其全部打包到 WAR 中。
您应该仔细阅读此内容。
如果您创建 foo.war 文件,并将其放在 Tomcat /webapps 目录中,您将使用以下 URL 访问它:
HTTP 404 意味着您没有正确注册您的 Web 应用程序。 Web 服务器/Tomcat 无法将资源与您提供的 URL 关联起来。
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:
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.
这篇文章不连贯:
您需要创建一个
WAR
,即具有关联 Web 描述符的 Web 应用程序,以便部署您的 Servlet。您在谈论哪个文件?这是Tomcat的Web管理界面的url
This post is not cohererent:
You need to create a
WAR
i.e. a web application with an associated web descriptor in order to deploy your servlets.Which file are you talking about? This is the url for Tomcat's web management interface