HttpRequest抽象类

  public abstract class HttpServlet extends GenericServlet

  实现的接口有:Serializable, Servlet, ServletConfig

  一、介绍

  提供一个抽象类,以便于子类创建适用于Web站点的HTTP Servlet。

  HttpServlet的子类,通常必须要实现至少一个方法,通常是下面这些:

  • doGet, if the servlet supports HTTP GET requests
  • doPost, for HTTP POST requests
  • doPut, for HTTP PUT requests
  • doDelete, for HTTP DELETE requests
  • init方法和destroy方法, to manage resources that are held for the life of the servlet
  • getServletInfo(), which the servlet uses to provide information about itself

  

  几乎没有理由来重写service方法。 service方法根据每个HTTP request的类型,将它们分配给相应的处理程序方法。(也就是说,具体的处理方法都是通过service方法来进行调度的)

  同样,几乎没有理由重写doOptions和doTrace方法。

  Servlet通常在多线程服务器上运行,因此请注意,servlet必须处理并发请求,并小心地同步对共享资源的访问。

  二、方法

  1、public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException

  将客户端请求分派给受保护的service方法,因此没有必要重写此方法。

  2、protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

  接收来自公共的service方法的标准HTTP请求,并将它们分派到此类中定义的doXXX方法。

  它是Servlet.service方法的HTTP特定版本,且没有必要重写。

  3、protected void doXXX()

  和http的请求类型有关:GET,POST,HEAD,PUT,DELETE,OPTIONS,TRACE

  4、protected long getLastModified(HttpServletRequest req)

  返回HttpServletRequest对象上次修改时间(以毫秒为单位),自从格林尼治标准时间1970年1月1日午夜。 如果时间未知,则此方法返回负数(默认值)。

  支持HTTP GET请求并可以快速确定最后修改时间的Servlet应覆盖此方法。 这使浏览器和代理缓存更有效地工作,减少了服务器和网络资源的负载。

Java EE javax.servlet.http中的HttpRequest抽象类的更多相关文章

  1. Java EE javax.servlet.http中的HttpSession接口

    HttpSession接口 public interface HttpSession (https://docs.oracle.com/javaee/7/api/javax/servlet/http/ ...

  2. Java EE javax.servlet中的ServletContext接口

    ServletContext接口 public interface ServletContext (https://docs.oracle.com/javaee/7/api/javax/servlet ...

  3. Java EE javax.servlet中的Servlet接口

    Servlet接口 public interface Servlet 其实现类有:FaceServlet.GenericServlet.HttpServlet 一.介绍 Servlet接口定义了所有s ...

  4. Java EE javax.servlet中的ServletResponse接口

    ServletResponse接口 public interface ServletResponse 子接口:HttpServletResponse 实现类:HttpServletResponseWr ...

  5. Java EE javax.servlet中的ServletRequest接口

    ServletRequest接口 public interface ServletRequest 子接口:HttpServletRequest 实现类:HttpServletRequestWrappe ...

  6. Java EE javax.servlet中的RequestDispatcher接口

    RequestDispatcher接口 public interface RequestDispatcher 一.介绍 定义一个对象,从客户端接收请求并将其发送到服务器上的任何资源(例如servlet ...

  7. Java EE javax.servlet中的ServletConfig接口

    ServletConfig接口 public interface ServletConfig 实现类:GenericServlet.HttpServlet 一.介绍 一个供servlet容器使用配置对 ...

  8. Java EE javax.servlet ServletContainerInitializer接口

    ServletContainerInitializer接口 public interface ServletContainerInitializer 一.介绍 该接口,允许在 web 应用程序的启动阶 ...

  9. 1,eclipse导入项目jdk版本不一样解决方案 2,java报javax.servlet.jsp cannot be resolved to a type

    一:eclipse导入项目jdk版本不一样解决方案 参考博文: https://www.cnblogs.com/chenmingjun/p/8472885.html 选中项目右键 --> Pro ...

随机推荐

  1. python获取最大值

    python2 中获取int最大值 import sys print sys.maxint 但是在python3中,报错: AttributeError: module 'sys' has no at ...

  2. Dubbo API 笔记——配置参考

    版权声明:欢迎转载,请注明出处,谢谢! https://blog.csdn.net/benhuo931115/article/details/78457391 schema 配置参考 所有配置项分为三 ...

  3. 转载: Windows下两种iocp实现的差距

    转自:http://blog.csdn.net/oldworm/article/details/6171430 之前几天说过,因为经典iocp实现(以下简称经典实现)多个io线程绑定在一个iocp上, ...

  4. ci 框架中defined('BASEPATH') OR exit('No direct script access allowed');

    作用: OR 就是前面的是true时,就不走后面了. 加这个是为了防止不是从index.php访问到的控制器

  5. hadoop新旧节点

    注意:黑白名单只出现在名称(nn)节点<!-- 白名单 --><property><name>dfs.hosts</name>/Users/yangya ...

  6. sklearn——train_test_split 随机划分训练集和测试集

    sklearn——train_test_split 随机划分训练集和测试集 sklearn.model_selection.train_test_split随机划分训练集和测试集 官网文档:http: ...

  7. babel 实践

    一.@babel/core var babel = require("@babel/core");babel.transform(code, options, function(e ...

  8. ubuntu下如何使用apt-get安装arm64的交叉编译工具链?

    答: sudo apt-get install gcc-aarch64-linux-gnu -y

  9. SRCNN代码分析

    代码是作者页面上下载的matlab版.香港中文大学汤晓鸥教授.Learning a Deep Convolutional Network for Image Super-Resolution. htt ...

  10. ubantu下docker安装

    开始安装 由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本: sudo apt-get remove docker docker-engine docker-ce docke ...