都需要注意什么呢?
是不是还要配置xml啊?
都不懂 大家别笑话我...

解决方案 »

  1.   


    import java.io.IOException;
    import java.io.PrintWriter;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class Simple extends HttpServlet { /**
     * Constructor of the object.
     */
    public Simple() {
    super();
    } /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    } /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out
    .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
    out.println("<HTML>");
    out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
    out.println("  <BODY>");
    out.print("    This is ");
    out.print(this.getClass());
    out.println(", using the GET method");
    out.println("  </BODY>");
    out.println("</HTML>");
    out.flush();
    out.close();
    } /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out
    .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
    out.println("<HTML>");
    out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
    out.println("  <BODY>");
    out.print("    This is ");
    out.print(this.getClass());
    out.println(", using the POST method");
    out.println("  </BODY>");
    out.println("</HTML>");
    out.flush();
    out.close();
    } /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occure
     */
    public void init() throws ServletException {
    // Put your code here
    }}
    //表示要使用一个Servlet 
    <servlet>  
          //在web.xml文件内部起作用的名字  
          <servlet-name>Simple</servlet-name>  
          //servlet程序所在包.类名称  
          <servlet-class>net.hialex.Servlet.SimpleServlet</servlet-class>       
    </servlet> 
    //servlet映射地址 
    <servlet-mapping>  
         //在web.xml文件内部起作用的名字,与上面的名字一致  
         <servlet-name>Simple</servlet-name>  
         //具体映射路径,前面必须要有一个/  
         <url-pattern>/demo</url-pattern>       
    </servlet-mapping> 
    你可以在myeclipse里面新建一个servlet看看代码是怎么样的
      

  2.   

    http://blog.chinaunix.net/u/21684/showart_195064.html
    含视频教程
      

  3.   

    恩,要用web.xml中配置servlet和它的映射关系。。
      

  4.   

    servlet 很简单只要了解一下它的生命周期就可以了。
    Servlet被服务器实例化后,容器运行其init方法,请求到达时运行其service方法,service方法自动派遣运行与请求对应的doXXX方法(doGet,doPost)等,当服务器决定将实例销毁的时候调用其destroy方法。