java - Tomcat 6.0 - 错误 404 请求的资源不可用

标签 java servlets tomcat6

我正在使用 Tomcat Servlet Engine(版本 6.0)开发 Servlet

我对这些东西完全是新手,所以我正在网上阅读一些东西。 现在我在以下位置创建 servlet 文件夹:

/var/lib/tomcat6/webapps/ROOT/myapp

在此下我创建 WEB-INF 文件夹和类之一。 所以我有这样的层次结构:

/var/lib/tomcat6/webapps/ROOT/myapp/WEB-INF/classes

我正在尝试执行这个简单的 servlet:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet{

    public void doGe(HttpServletRequest request, HttpServletResponse response)
    throws IOException {
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<h1>Hello Servlet!</h1>");
        out.println("</body>");
        out.println("</html>"); 
    }
}

编译后我把.class文件放在classes目录下,然后我在WEB-INF目录下创建了web.xml文件,内容如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5"> 

    <description>
      Servlet and JSP Examples.
    </description>
    <display-name>Servlet and JSP Examples</display-name>

    <servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>TestServlet</servlet-class>
    </servlet>


    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
</web-app>

然后我只需转到:

   http://localhost:8080/myapp/test

但我收到 404 错误。

我能做什么?提前致谢

最佳答案

将文件夹从ROOT移动到webapp,文件夹结构应该是

/var/lib/tomcat6/webapps/myapp

Documentation

关于java - Tomcat 6.0 - 错误 404 请求的资源不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12510304/

相关文章:

spring - 在服务器:"INFO: Initializing Spring root WebApplicationContext"中部署spring应用程序时Tomcat崩溃

session - 如何在 Tomcat 中保持 HttpSession 事件?

java - 我们可以在一个方法中有一个内部类吗?

java - ShakeService.java 通过 Intent 调用后不打印 Log 消息

java - 使用包含反斜杠的 URL 中的参数处理 POST 请求

java - 修复将数据从一个 servlet 传递到另一个 servlet 的问题

java - SAP Hybris : How to load app context in custom error page controller?

linux - shared.loader="${catalina.home}/shared/classes 不能在 LINUX 上运行,但可以在 WINDOWS 上运行

java - 使文本文件可用于 Java 中的所有方法

java - 存储数据类型<?在类字段中扩展 T>