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