{"id":166229,"date":"2019-12-25T09:00:11","date_gmt":"2019-12-25T01:00:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=166229"},"modified":"2019-12-10T12:56:52","modified_gmt":"2019-12-10T04:56:52","slug":"tomcat-and-servlet-containers","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/tomcat-and-servlet-containers.html","title":{"rendered":"Tomcat\u4e0eServlet\u5bb9\u5668"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u201cTomcat\u662f\u4e00\u4e2aServlet\u5bb9\u5668\u201d\uff0c\u8fd9\u53e5\u8bdd\u5bf9\u4e8e2019\u5e74\u7684\u7a0b\u5e8f\u5458\u5e94\u8be5\u662f\u8033\u719f\u80fd\u8be6\u7684\u3002\u4eca\u5929\u6211\u4eec\u5c31\u6765\u4e00\u8d77\u4e86\u89e3\u4e00\u4e0b\u5728Tomcat\u4e2d\u7684\u56db\u4e2a\u5bb9\u5668\uff1aWrapper\u3001Context\u3001Host\u3001Engine<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

Context<\/strong><\/div>\n

\u987e\u540d\u601d\u4e49\uff0cServlet\u5bb9\u5668\u5c31\u662f\u7528\u6765\u88c5\u8f7d\u5b58\u50a8Servlet\u7684\u3002<\/p>\n

\u4e00\u4e2aServlet\u8868\u793a\u4e00\u4e2a\u8fd0\u884c\u5728\u670d\u52a1\u7aef\u7684\u7a0b\u5e8f(servlet = server + applet)\u3002\u7528\u6237\u60f3\u8981\u4f7f\u7528\u8fd9\u79cd\u7a0b\u5e8f\uff0c\u9700\u8981\u5411\u8be5\u7a0b\u5e8f\u53d1\u9001\u8bf7\u6c42\u4ee5\u53ca\u83b7\u53d6\u8be5\u7a0b\u5e8f\u7684\u54cd\u5e94\uff0c\u4e5f\u5c31\u662fServlet\u89c4\u8303\u4e2d\u7684ServletRequest\u3001ServletResponse\u3002<\/p>\n

\u6240\u4ee5Servlet\u5176\u5b9e\u5c31\u662fJava\u4e2d\u7528\u6765\u5904\u7406\u8bf7\u6c42\u7684\u4e00\u79cd\u89c4\u8303\uff0c\u6240\u4ee5\u6211\u4eec\u7684\u9879\u76ee\u4e2d\u901a\u5e38\u90fd\u4f1a\u6709\u4e00\u4e2a\u6216\u591a\u4e2aServlet\uff0c\u7531\u5b83\u6765\u8d1f\u8d23\u63a5\u6536\u8bf7\u6c42\uff0c\u6216\u8005\u5c06\u8bf7\u6c42\u8f6c\u4ea4\u7ed9\u5176\u4ed6\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n

\u6240\u4ee5\u6211\u4eec\u7684Spring MVC\u3001Spring Boot\u90fd\u5b58\u5728\u4e00\u4e2aDispatcherServlet(\u7c7b\u4f3c\u529f\u80fd\u7684\u4e00\u4e2aServlet\uff0c\u8d1f\u8d23\u63a5\u6536\u8bf7\u6c42)\u3002<\/p>\n

\u6240\u4ee5\uff0c\u901a\u5e38Servlet\u662f\u5c5e\u4e8e\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f(\u9879\u76ee)\u7684\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u7684\u4e00\u4e2a\u5e94\u7528\u5305\u542b\u591a\u4e2aServlet\uff0c\u6240\u4ee5\u8fd9\u662f\u7b2c\u4e8c\u5c42Servlet\u5bb9\u5668--\u5e94\u7528\uff0c\u4e5f\u5c31\u662fTomcat\u4e2d\u7684Context(\u5e94\u7528\u4e0a\u4e0b\u6587)\u3002\u90a3\u4e48\u7b2c\u4e00\u5c42Servlet\u5bb9\u5668\u5462?<\/p>\n

Wrapper<\/strong><\/div>\n

Wrapper\u5c31\u662f\u7b2c\u4e00\u5c42Servlet\u5bb9\u5668\uff0cWrapper\u8868\u793aServlet\u7684\u5305\u88c5\u8005\uff0c\u6240\u4ee5\u5b83\u662f\u6700\u63a5\u8fd1Servlet\u7684\uff0c\u90a3\u4e48\u4e3a\u4ec0\u4e48\u9700\u8981Wrapper\u5462?<\/p>\n

\u6211\u4eec\u901a\u5e38\u8ba4\u4e3aWrapper\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n

\u4e00\u4e2aWrapper\u5bf9\u5e94\u4e00\u4e2aServlet\uff0c\u8fd9\u4e48\u6765\u60f3\u7684\u8bdd\uff0c\u786e\u5b9e\u4e0d\u9700\u8981Wrapper\uff0c\u4f46\u662f\u6211\u4eec\u8fd8\u8981\u8003\u8651\u4e00\u4e9b\u5176\u4ed6\u7684\u60c5\u51b5\uff1a<\/p>\n

    \u6bd4\u5982Filter\uff0c\u4e00\u4e2aFilter\u662f\u53ef\u4ee5\u5bf9\u5e94\u4e00\u4e2aServlet\u7684\u3002<\/ol>\n
      \u6bd4\u5982ServletPool\uff0c\u901a\u5e38\u7684Servlet\u662f\u6240\u6709\u8bf7\u6c42\u7ebf\u7a0b\u516c\u7528\u7684\uff0c\u4f46\u662f\u5728Servlet\u4e2d\u652f\u6301\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u7ebf\u7a0b\u5355\u72ec\u4f7f\u7528\u72ec\u7acb\u7684Servlet\u5b9e\u4f8b\u3002<\/ol>\n

      \u6240\u4ee5\u5728Wrapper\u4e2d\uff0c\u4e0d\u4ec5\u4ec5\u53ea\u5305\u62ec\u4e00\u4e2aServlet\uff0c\u8fd8\u5305\u62ec\u8fc7\u6ee4\u5668\u548cServlet\u6c60\uff0c\u6240\u4ee5Wrapper\u662f\u7b2c\u4e00\u5c42Servlet\u5bb9\u5668\u3002<\/p>\n

      Host<\/strong><\/div>\n

      \u5728\u6211\u4eec\u73b0\u5b9e\u751f\u6d3b\u4e2d\uff0c\u4e00\u4e2a\u5e94\u7528\u90fd\u662f\u90e8\u7f72\u5728\u4e00\u4e2a\u4e3b\u673a\u4e0a\u7684\uff0c\u6240\u4ee5\uff0c\u4e00\u4e2a\u4e3b\u673a\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u5e94\u7528\uff0c\u4e00\u4e2a\u5e94\u7528\u5305\u542b\u591a\u4e2aServlet\uff0c\u6240\u4ee5\uff0cHost\u662f\u7b2c\u4e09\u5c42\u5bb9\u5668\u3002<\/p>\n

      \u5728Tomcat\u4e2d\uff0cHost\u8868\u793a\u865a\u62df\u4e3b\u673a\uff0cTomcat\u5728\u5904\u7406\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u8bf7\u6c42\u7684\u57df\u540d\u8fdb\u5165\u5230\u76f8\u5e94\u7684Host\u4e2d\u8fdb\u884c\u5904\u7406\u3002<\/p>\n

      Engine<\/strong><\/div>\n

      Host\u7ba1\u7406Context\uff0cContext\u7ba1\u7406Wrapper\uff0cWrapper\u7ba1\u7406Servlet\uff0c\u800cEngine\u5c31\u662f\u7528\u6765\u7ba1\u7406Host\u7684\u3002\u6240\u4ee5Engine\u662f\u7b2c\u56db\u5c42\u5bb9\u5668\u3002<\/p>\n

      \u6700\u540e<\/strong><\/div>\n

      \u80af\u5b9a\u6709\u4eba\u6709\u7591\u95ee\uff0c\u90a3\u4e48Engine\u4e4b\u4e0a\u4e0d\u9700\u8981\u5bb9\u5668\u4e86\u5417?\u4e0d\u9700\u8981\u4e86?\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n

      \u6211\u4eec\u7684\u94b1(Servlet)\u8981\u653e\u5728\u94b1\u5305(Wrapper)\u91cc\uff0c\u94b1\u5305\u8981\u653e\u5728\u4e66\u5305(Context)\u91cc\uff0c\u4e66\u5305\u8981\u653e\u5728\u884c\u674e\u7bb1(Host)\u91cc\uff0c\u884c\u674e\u7bb1\u8981\u653e\u5728\u98de\u673a(Engine)\u4e0a\u3002<\/p>\n

      \u6240\u4ee5\uff0c\u5982\u679c\u4f60\u95ee\u6211\u201cEngine\u653e\u54ea?\u201d\u5c31\u76f8\u5f53\u4e8e\u95ee\u6211\u201c\u98de\u673a\u653e\u54ea?\u201d<\/p>\n

      \u7b54\u6848\u662f\u4e0d\u518d\u9700\u8981\u66f4\u9ad8\u5c42\u6b21\u7684\u5bb9\u5668\u4e86\uff0c\u56e0\u4e3a\u6ca1\u6709\u5fc5\u8981\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

      \u987e\u540d\u601d\u4e49\uff0cServlet\u5bb9\u5668\u5c31\u662f\u7528\u6765\u88c5\u8f7d\u5b58\u50a8Servlet\u7684\u3002 \u4e00\u4e2aServlet\u8868\u793a\u4e00\u4e2a\u8fd0\u884c\u5728\u670d\u52a1\u7aef\u7684\u7a0b\u5e8f( […]<\/p>\n","protected":false},"author":1329,"featured_media":166232,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-166229","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/166229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=166229"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/166229\/revisions"}],"predecessor-version":[{"id":166235,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/166229\/revisions\/166235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/166232"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=166229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=166229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=166229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}