package mypackage;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class Hello extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
out.println("Hello, world!");
out.close();
}
}
web.xml文件如下:基本Tomcat的Servlet的錯誤
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Hello, World Application</display-name>
<description>
This is a simple web application with a source code organization
based on the recommendations of the Application Developer's Guide.
</description>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
我然後做所有的螞蟻,螞蟻重裝也/etc/init.d/tomcat重啓
但我得到這個錯誤的瀏覽器:
HTTP狀態404 - /你好/
類型狀態報告
留言/你好/
description請求的資源(/ hello /)不可用。 Apache Tomcat/6.0.26
什麼可能是錯的?
聽起來像是你的web應用程序不部署到tomcat的。你的tomcat是否安裝了經理servlet?這可以幫助。另外,將servlet映射中的url模式更改爲「/ *」。 – John 2010-04-05 01:26:12
我改變了我的web.xml,做了所有的螞蟻,然後螞蟻重新加載。仍然我的web.xml沒有被複制到tomcat webapps/hello/WEB-INF文件夾。爲什麼? – user855 2010-04-05 02:15:51