Servlet - Tomcat 路径

发布于 2024-12-29 16:04:09 字数 494 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帝王念 2025-01-05 16:04:09

设置 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://localhost:8080/foo/<servlet-name-here>

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:

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.

雪落纷纷 2025-01-05 16:04:09

这篇文章不连贯:

为了运行 servlet 应用程序,我编译了 servlet 程序并
生成了类文件。我可以轻松地编译我的程序并获得
类文件。

您需要创建一个 WAR,即具有关联 Web 描述符的 Web 应用程序,以便部署您的 Servlet。

但是当我尝试运行 tomcat http://localhost:8080/ 它给了我
状态码 404 - 文件不

您在谈论哪个文件?这是Tomcat的Web管理界面的url

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文