Servlet - Tomcat 路径 [英] Servlet - Tomcat Path

查看:56
本文介绍了Servlet - Tomcat 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 servlet 引擎有问题,即 Tomcat.我使用 Windows-7 作为我的操作系统.我已将 Tomcat 安装到此文件夹 C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0.

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"

C:>SET CLASSPATH="C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"

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

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.

但是当我尝试运行 tomcat http://localhost:8080/ 时,它给了我状态代码 404- 找不到文件..为什么会这样??

But when i try to run the tomcat http://localhost:8080/ it gives me the status code 404 - File not Found..Why so??

谢谢...

推荐答案

设置 CLASSPATH 是不必要的,甚至是不可取的.我使用的任何机器上都没有 CLASSPATH 环境变量.Tomcat 知道 servlet.jar 在哪里.您的应用程序需要它才能编译,但正确的做法是使用 -classpath 命令行选项包含该 JAR.

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.

您的 servlet 是否在包中?Tomcat 不允许使用不在包中的 servlet 或类.

Is your servlet in a package? Tomcat doesn't allow servlets or classes that aren't in packages.

您是否将 servlet 打包到 WAR 文件中?那将是一个好主意.使用标准目录结构,将您的 servlet .class 文件放在 WEB-INF/classes 目录中,创建一个描述您的 servlet 的 web.xml 文件,并将其全部打包到一个 WAR 中.

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.

你应该仔细阅读这个.

如果您创建一个 foo.war 文件,并将其放在 Tomcat/webapps 目录中,您将使用以下 URL 访问它:

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>

HTTP 404 表示您没有正确注册您的网络应用.Web 服务器/Tomcat 无法将资源与您提供的 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.

这篇关于Servlet - Tomcat 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆