我正在使用 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 错误。
我能做什么?提前致谢
最佳答案
关于java - Tomcat 6.0 - 错误 404 请求的资源不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12510304/