Java核心代码例程之:Servlet----SimpleServlet.java

发表于:2007-06-22来源:作者:点击数: 标签:
import java .io.*; importjavax.servlet.*; importjavax.servlet.http.*; publicclassSimpleServlet extendsHttpServlet { publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException { ServletOutputSt

   
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class SimpleServlet
       extends HttpServlet
{

    public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException
    {
        ServletOutputStream sos = response.getOutputStream();
        sos.println("<h1>doGet: Hello World!</h1>");
    }
    
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException
    {
        ServletOutputStream sos = response.getOutputStream();
        sos.println("<h1>doPost: Hello World!</h1>");
    }
    

    /*
    // Instead of calling doGet() or doPost(), service() can aclearcase/" target="_blank" >ccomodate both 
    public void service(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException
    {
    }
    **/
}

原文转自:http://www.ltesting.net