刚学servlet 做了第一个简单的案例,但是貌似配置xml文件的时候出错了,用tomcat运行时出现错误,请各位指教
package com.ct
import javax.servlet.*;
import java.io.*;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;public class Hello implements Servlet
{

//该函数用于初始化servlet(类似于类的构造函数)
//该函数只会被调用一次(当用户第一次访问该servlet时被调用)

public void init(ServletConfig parm1) throws ServletException {
System.out.println("init it");

}
public ServletConfig getServletConfig() {

return null;
} //该函数用于处理业务逻辑
//当用户每访问一次的时候都会被调用
//req用于获得客户端信息,res用于向客户端返回信息
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
Printwriter pw=res.getWriter();
pw.println("hello");
}
public String getServletInfo() {


}
    //释放内存
public void destroy() {
System.out.println("关闭");
}

}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.
-->

解决方案 »

  1.   

    这个类不应该是继承HttpServlet的吗
    web.xml文件也没配置servlet
      

  2.   

    同意1楼。另外,
    Servlet开发的步骤都是:
      ⑴打开MyEclipse开发环境,创建一个WEB项目。
      ⑵创建一个类,该类继承了javax.servlet.http包中的HttpServlet类。
      ⑶在新创建的类中重写doGet()和doPost()方法。
      ⑷在web.xml中进行相关注册。
      ⑸在服务器上发布该项目。
      ⑹根据web.xml中的配置信息,访问编写的Servlet。