import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class firstServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void service(HttpServletRequest request,HttpServletResponse response) throws IOException
{
       response.setContentType("text/html;charset=gb2312");
   PrintWriter out=response.getWriter();
   out.println("<html><body>");
   out.println("这是一个简单的Servlet.");
   out.println("客户端的地址是:"+request.getRemoteAddr()+"<br>");
   out.println("/body></html><");
}
}

解决方案 »

  1.   

    程序中有些地方是有问题的,
    1.类名首字母要大写FirstServlet
    2.代码最后一行多了个“<”.
      

  2.   

    sorry,编译后程序出现这样的情况:
    C:\Documents and Settings\NLP\桌面\firstServlet.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:4: cannot find symbol
    symbol: class HttpServlet
    public class firstServlet extends HttpServlet
                                      ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:6: cannot find symbol
    symbol  : class ServletConfig
    location: class firstServlet
            public void init(ServletConfig config) throws ServletException
                             ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:6: cannot find symbol
    symbol  : class ServletException
    location: class firstServlet
            public void init(ServletConfig config) throws ServletException
                                                          ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:10: cannot find symbol
    symbol  : class HttpServletRequest
    location: class firstServlet
            public void service(HttpServletRequest request,HttpServletResponse response) throws IOException
                                ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:10: cannot find symbol
    symbol  : class HttpServletResponse
    location: class firstServlet
            public void service(HttpServletRequest request,HttpServletResponse response) throws IOException
                                                           ^
    C:\Documents and Settings\NLP\桌面\firstServlet.java:8: cannot find symbol
    symbol  : variable super
    location: class firstServlet
                    super.init(config);
                    ^
    8 errors
    我的CLASSPATH是:.;E:\Tomcat 5.0\common\lib\servlet-api.jar;E:\NetMediaMonit\JDK1.5.0\lib\tools.jar;
      

  3.   

    楼上的应该找一下servlet的配置与部署
    网上有很多这方面的