刚开始很模糊他们的关系,不清楚

service

protected void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException
Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method. There's no need to override this method.
Parameters:
req - the HttpServletRequest object that contains the request the client made of the servlet
resp - the HttpServletResponse object that contains the response the servlet returns to the client
Throws:
java.io.IOException - if an input or output error occurs while the servlet is handling the TRACE request
ServletException - if the request for the TRACE cannot be handled
See Also:
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
查看源代码:反编译工具打开j2ee13.jar,定位到javax.servlet.http.HttpServlet,可以看到service的代码
  protected void service(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    long lastModified;
    String method = req.getMethod();

if (method.equals("GET")) {
      lastModified = getLastModified(req);
      if (lastModified == -1L)
      {
        doGet(req, resp);
      } else {
        long ifModifiedSince = req.getDateHeader("If-Modified-Since");
        if (ifModifiedSince < lastModified / 1000L * 1000L)
        {
          maybeSetLastModified(resp, lastModified);
          doGet(req, resp);
        } else {
          resp.setStatus(304);
        }
      }
    }
    else if (method.equals("HEAD")) {
      lastModified = getLastModified(req);
      maybeSetLastModified(resp, lastModified);
      doHead(req, resp);
    }
    else if (method.equals("POST")) {
      doPost(req, resp);
    }
    else if (method.equals("PUT")) {
      doPut(req, resp);
    }
    else if (method.equals("DELETE")) {
      doDelete(req, resp);
    }
    else if (method.equals("OPTIONS")) {
      doOptions(req, resp);
    }
    else if (method.equals("TRACE")) {
      doTrace(req, resp);
    }
    else
    {
      String errMsg = lStrings.getString("http.method_not_implemented");
      Object[] errArgs = new Object[1];
      errArgs[0] = method;
      errMsg = MessageFormat.format(errMsg, errArgs);

resp.sendError(501, errMsg);
    }
  }

结论:当客户端请求服务器servlet,request对象封装了请求的数据,servlet通过service方法通过请求方式的不同(get,post...)来跳转(dispacher)到对应的doXXX方法。

[需要补充]javaEE中servlet方法service与doXXX的关系的更多相关文章

  1. Servlet的Service方法和doget 和 dopost方法的区别,常见的错误解析

    package com.sxt.in; import java.io.IOException; import javax.servlet.ServletException; import javax. ...

  2. javaWEB中的ServletRequest,ServletResponse的使用,及简化Servlet方法

    首先说一下ServletRequest,ServletResponse类的使用方法: public void service(ServletRequest request, ServletRespon ...

  3. Java第三阶段学习(十一、Servlet基础、servlet中的方法、servlet的配置、ServletContext对象)

    一.Servlet简介  1.什么是servlet: sun公司提供的一套规范(接口),用来处理客户端请求.响应给浏览器的动态资源.但servlet的实质就是java代码,通过java的API动态的向 ...

  4. android 中activity调用本地service中的方法。

    1.自定义一个接口,暴露服务中的方法 public interface IService {    /**服务中对外暴露的方法 */    void methodInService();} 2.自定一 ...

  5. 用JQuery中的Ajax方法获取web service等后台程序中的方法

    用JQuery中的Ajax方法获取web service等后台程序中的方法 1.准备需要被前台html页面调用的web Service,这里我们就用ws来代替了,代码如下: using System; ...

  6. Visual Studio 2013中引入Web Service的简单方法visual studio 引用 wsdl

    http://blog.csdn.net/wangzhongbo_24/article/details/49954191 Web Service有三种表示方式 三种方式分别为WSDL.Endpoint ...

  7. 【mybatis】service层中一个方法中使用mybatis进行数据库的 多个修改操作,可能是update也可能是delete操作,但是sql语句命名执行并且在控制台打印出来了,但是数据库中未更新到数据【事务的问题】

    问题描述: service层中一个方法中使用mybatis进行数据库的 多个修改操作,可能是update也可能是delete操作,但是sql语句命名执行并且在控制台打印出来了,但是数据库中未更新到数据 ...

  8. 面向对象中特殊方法的补充、isinstance/issubclass/type、方法和函数、反射

    一.面向对象中特殊方法的补充 1.__str__ 能将对象名改成你想要的字符串,但是类型还是类 class Foo(object): def __init__(self): pass def func ...

  9. 反射实现定位Servlet中的方法

    public class BaseServlet extends HttpServlet{ @Override protected void service(HttpServletRequest re ...

随机推荐

  1. 【angular2+typeScript+ng-zorro】Carousel 走马灯的左右方向控件实现

    ng-zorro Carousel 走马灯的左右方向控件实现 ng-zorro框架的走马灯本身还没有左右方向控件的实现,作者只是在文档中(0.6x)中曝出几个方法接口,如图: 实现: 在根compon ...

  2. Python3基础 set add 向集合中加入新的元素

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  4. Unity3D学习笔记(八):四元素和书籍推荐

    书籍推荐: 3D数学基础:图形与游戏开发——游戏软件开发专家系列(美)邓恩 Unity Shader入门精要 冯乐乐(92年) 数据结构(Python语言描述) 数据结构.算法与应用(C++语言描述) ...

  5. 01_Spark基础

    1.1.Spark Ecosystem BlinkDB: 允许用户定义一个错误范围,BlinkDB将在用户给定的错误范围内,尽可能快的提供查询结果 1.2.Spark愿景 1.3.Spark简介 1) ...

  6. 适用于目前环境的bug记录

    问测试,bugtracker.JIRA,你们用起来啊? 难道bugtracker/JIRA只有测试用吗? 截屏忽略,只有测试人员自己提bug,开发不管不顾,解决了也不关闭bug,bug提得太多,还嫌测 ...

  7. [ios]如何在ARC代码中混编非ARC代码

    参考 :http://blog.sina.com.cn/s/blog_b595ce9e0101nvvn.html “ios中如果arc和非arc文件混编,可以在build parses中指定compi ...

  8. Codeforces 918C - The Monster

    918C - The Monster 思路1: 右键在新窗口打开图片 代码: #include<bits/stdc++.h> using namespace std; #define ll ...

  9. spring boot: thymeleaf模板引擎使用

    spring boot: thymeleaf模板引擎使用 在pom.xml加入thymeleaf模板依赖 <!-- 添加thymeleaf的依赖 --> <dependency> ...

  10. 【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(二)

      五.Graphics layer 1.新增Graphics layer Graphics layer用于显示用户自定义绘制的点.线.面图形.使用时确保xaml文件中Graphics layer定义 ...