Servlet应用 —— HTTPServlet类
由于大多数Web应用都是通过HTTP协议和客户端进行交互,因此,在Servlet接口中,提供了一个抽象类javax.http.HttpServlet,它是GenericServlet的子类,专门用于创建应用于HTTP协议的Servlet。为了更好的了解HTTPServlet,接下来,看一下HTTPServlet类的源码,
public abstract class HttpServlet extends GenericServlet{
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String method = req.getMethod();
if (method.equals(METHOD_GET)) {
long lastModified = getLastModified(req);
if (lastModified == -1) {
// servlet doesn't support if-modified-since, no reason
// to go through further expensive logic
doGet(req, resp);
} else {
long ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);
if (ifModifiedSince < lastMod