我手工用tomcat自己部署了一个程序,编译也没有问题,程序如下:
package com.hu;
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 Hello extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res){
try {
PrintWriter pw = res.getWriter();
pw.println("hello world!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res){
this.doGet(req, res);
}
}
在地址栏中输入http://localhost:8080/myWebSite/hello,出现404错误
web.xml的配置如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
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">
Welcome to Tomcat
Welcome to Tomcat
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.hu.Hello</servlet-class>
<servlet-mapping>hello</servlet-mapping>
<url-pattern>/hello</url-pattern>