抽象类HttpServlet是GenericServlet类的子类,HttpServlet类为Servlet接口提供了与Http协议相关的通用实现,也就是说,HttpServlet对象适合运行在与客户端采用Http协议通信的Servlet容器或者web服务器中,在开发JavaWeb应用中,自定义的Servlet类一般都扩展HttpServlet类。我们来看一下HttpServlet类的源代码(只摘录部分):
public abstract class HttpServlet extends GenericServlet
implements java.io.Serializable{
private static final String METHOD_GET = "GET";
private static final String METHOD_POST = "POST";
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException{
HttpServletRequest request;
HttpServletResponse response;
try{
request=(HttpServletRequest)req;
response=(HttpServletResponse)res;
}catch(ClassCastException e){
throw new ServletException("non-HTTP request or response");
}
service(request,response);
}
protected void