zoukankan      html  css  js  c++  java
  • Java EE javax.servlet.http中的HttpRequest抽象类

    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应覆盖此方法。 这使浏览器和代理缓存更有效地工作,减少了服务器和网络资源的负载。

     

     

  • 相关阅读:
    两种解决IE6不支持固定定位的方法
    DIV+CSS IE6/IE7/IE8/FF兼容问题汇总
    解决IE6兼容性问题的十一大技巧
    解决 IE6 背景缓存
    C#用正则表达式 获取网页源代码标签的属性或值
    js中addEventListener中第3个参数
    jquery ready方法实现原理 内部原理
    jQuery动画animate方法使用介绍
    GetParam(name)
    js未分类
  • 原文地址:https://www.cnblogs.com/bigbigbigo/p/8845549.html
Copyright © 2011-2022 走看看