gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:12:22 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com