{"id":191125,"date":"2020-05-27T08:11:26","date_gmt":"2020-05-27T00:11:26","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=191125"},"modified":"2020-05-17T16:12:37","modified_gmt":"2020-05-17T08:12:37","slug":"tomcat-structure-analysis","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/tomcat-structure-analysis.html","title":{"rendered":"Tomcat\u5185\u90e8\u7ed3\u6784\u89e3\u6790"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nTomcat\u662f\u4e00\u4e2aJSP\/Servlet\u5bb9\u5668\u3002\u5176\u4f5c\u4e3aServlet\u5bb9\u5668\uff0c\u6709\u4e09\u79cd\u5de5\u4f5c\u6a21\u5f0f\uff1a\u72ec\u7acb\u7684Servlet\u5bb9\u5668\u3001\u8fdb\u7a0b\u5185\u7684Servlet\u5bb9\u5668\u548c\u8fdb\u7a0b\u5916\u7684Servlet\u5bb9\u5668\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
Tomcat\u7684\u7ec4\u7ec7\u7ed3\u6784<\/strong><\/div>\n

Tomcat\u662f\u4e00\u4e2a\u57fa\u4e8e\u7ec4\u4ef6\u7684\u670d\u52a1\u5668\uff0c\u5b83\u7684\u6784\u6210\u7ec4\u4ef6\u90fd\u662f\u53ef\u914d\u7f6e\u7684\uff0c\u5176\u4e2d\u6700\u5916\u5c42\u7684\u662fCatalina servlet\u5bb9\u5668\uff0c\u5176\u4ed6\u7ec4\u4ef6\u6309\u7167\u4e00\u5b9a\u7684\u683c\u5f0f\u8981\u6c42\u914d\u7f6e\u5728\u8fd9\u4e2a\u9876\u5c42\u5bb9\u5668\u4e2d\u3002<\/p>\n

Tomcat\u7684\u5404\u79cd\u7ec4\u4ef6\u90fd\u662f\u5728Tomcat\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684\/conf\/server.xml\u6587\u4ef6\u4e2d\u914d\u7f6e\u7684\u3002<\/p>\n

\u7531Server.xml\u7684\u7ed3\u6784\u770bTomcat\u7684\u4f53\u7cfb\u7ed3\u6784<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u7531\u4e0a\u53ef\u5f97\u51faTomcat\u7684\u4f53\u7cfb\u7ed3\u6784\uff1a<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u7531\u4e0a\u56fe\u53ef\u770b\u51faTomca\u7684\u5fc3\u810f\u662f\u4e24\u4e2a\u7ec4\u4ef6\uff1aConnecter\u548cContainer\u3002\u4e00\u4e2aContainer\u53ef\u4ee5\u9009\u62e9\u591a\u4e2aConnecter\uff0c\u591a\u4e2aConnector\u548c\u4e00\u4e2aContainer\u5c31\u5f62\u6210\u4e86\u4e00\u4e2aService\u3002Service\u53ef\u4ee5\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u800cServer\u670d\u52a1\u5668\u63a7\u5236\u6574\u4e2aTomcat\u7684\u751f\u547d\u5468\u671f\u3002<\/p>\n

    \u7ec4\u4ef6\u7684\u751f\u547d\u7ebf\u201cLifecycle\u201d<\/ol>\n
      Service \u548c Server \u7ba1\u7406\u5b83\u4e0b\u9762\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f\u3002<\/ol>\n
        Tomcat \u4e2d\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f\u662f\u901a\u8fc7 Lifecycle \u63a5\u53e3\u6765\u63a7\u5236\u7684\uff0c\u7ec4\u4ef6\u53ea\u8981\u7ee7\u627f\u8fd9\u4e2a\u63a5\u53e3\u5e76\u5b9e\u73b0\u5176\u4e2d\u7684\u65b9\u6cd5\u5c31\u53ef\u4ee5\u7edf\u4e00\u88ab\u62e5\u6709\u5b83\u7684\u7ec4\u4ef6\u63a7\u5236\u4e86\uff0c\u8fd9\u6837\u4e00\u5c42\u4e00\u5c42\u7684\u76f4\u5230\u4e00\u4e2a\u6700\u9ad8\u7ea7\u7684\u7ec4\u4ef6\u5c31\u53ef\u4ee5\u63a7\u5236 Tomcat \u4e2d\u6240\u6709\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f\uff0c\u8fd9\u4e2a\u6700\u9ad8\u7684\u7ec4\u4ef6\u5c31\u662f Server\uff0c\u800c\u63a7\u5236 Server \u7684\u662f Startup\uff0c\u4e5f\u5c31\u662f\u60a8\u542f\u52a8\u548c\u5173\u95ed Tomcat\u3002<\/ol>\n
        Tomca\u7684\u4e24\u5927\u7ec4\u4ef6\uff1aConnecter\u548cContainer<\/strong><\/div>\n
        Connecter\u7ec4\u4ef6<\/strong><\/span><\/div>\n

        \u4e00\u4e2aConnecter\u5c06\u5728\u67d0\u4e2a\u6307\u5b9a\u7684\u7aef\u53e3\u4e0a\u4fa6\u542c\u5ba2\u6237\u8bf7\u6c42\uff0c\u63a5\u6536\u6d4f\u89c8\u5668\u7684\u53d1\u8fc7\u6765\u7684 tcp \u8fde\u63a5\u8bf7\u6c42\uff0c\u521b\u5efa\u4e00\u4e2a Request \u548c Response \u5bf9\u8c61\u5206\u522b\u7528\u4e8e\u548c\u8bf7\u6c42\u7aef\u4ea4\u6362\u6570\u636e\uff0c\u7136\u540e\u4f1a\u4ea7\u751f\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42\u5e76\u628a\u4ea7\u751f\u7684 Request \u548c Response \u5bf9\u8c61\u4f20\u7ed9\u5904\u7406Engine(Container\u4e2d\u7684\u4e00\u90e8\u5206)\uff0c\u4eceEngine\u51fa\u83b7\u5f97\u54cd\u5e94\u5e76\u8fd4\u56de\u5ba2\u6237\u3002<\/p>\n

        Tomcat\u4e2d\u6709\u4e24\u4e2a\u7ecf\u5178\u7684Connector\uff0c\u4e00\u4e2a\u76f4\u63a5\u4fa6\u542c\u6765\u81eaBrowser\u7684HTTP\u8bf7\u6c42\uff0c\u53e6\u5916\u4e00\u4e2a\u6765\u81ea\u5176\u4ed6\u7684WebServer\u8bf7\u6c42\u3002Cotote HTTP\/1.1 Connector\u5728\u7aef\u53e38080\u5904\u4fa6\u542c\u6765\u81ea\u5ba2\u6237Browser\u7684HTTP\u8bf7\u6c42\uff0cCoyote JK2 Connector\u5728\u7aef\u53e38009\u5904\u4fa6\u542c\u5176\u4ed6Web Server\u7684Servlet\/JSP\u8bf7\u6c42\u3002<\/p>\n

        Connector \u6700\u91cd\u8981\u7684\u529f\u80fd\u5c31\u662f\u63a5\u6536\u8fde\u63a5\u8bf7\u6c42\u7136\u540e\u5206\u914d\u7ebf\u7a0b\u8ba9 Container \u6765\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42\uff0c\u6240\u4ee5\u8fd9\u5fc5\u7136\u662f\u591a\u7ebf\u7a0b\u7684\uff0c\u591a\u7ebf\u7a0b\u7684\u5904\u7406\u662f Connector \u8bbe\u8ba1\u7684\u6838\u5fc3\u3002<\/p>\n

        Container\u7ec4\u4ef6<\/strong><\/span><\/div>\n

        Container\u7684\u4f53\u7cfb\u7ed3\u6784\u5982\u4e0b\uff1a
        \n\"\"<\/p>\n

        Container\u662f\u5bb9\u5668\u7684\u7236\u63a5\u53e3\uff0c\u8be5\u5bb9\u5668\u7684\u8bbe\u8ba1\u7528\u7684\u662f\u5178\u578b\u7684\u8d23\u4efb\u94fe\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5b83\u7531\u56db\u4e2a\u81ea\u5bb9\u5668\u7ec4\u4ef6\u6784\u6210\uff0c\u5206\u522b\u662fEngine\u3001Host\u3001Context\u3001Wrapper\u3002\u8fd9\u56db\u4e2a\u7ec4\u4ef6\u662f\u8d1f\u8d23\u5173\u7cfb\uff0c\u5b58\u5728\u5305\u542b\u5173\u7cfb\u3002\u901a\u5e38\u4e00\u4e2aServlet class\u5bf9\u5e94\u4e00\u4e2aWrapper\uff0c\u5982\u679c\u6709\u591a\u4e2aServlet\u5b9a\u4e49\u591a\u4e2aWrapper\uff0c\u5982\u679c\u6709\u591a\u4e2aWrapper\u5c31\u8981\u5b9a\u4e49\u4e00\u4e2a\u66f4\u9ad8\u7684Container\uff0c\u5982Context\u3002<\/p>\n

        Context \u8fd8\u53ef\u4ee5\u5b9a\u4e49\u5728\u7236\u5bb9\u5668 Host \u4e2d\uff0cHost \u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u4f46\u662f\u8981\u8fd0\u884c war \u7a0b\u5e8f\uff0c\u5c31\u5fc5\u987b\u8981 Host\uff0c\u56e0\u4e3a war \u4e2d\u5fc5\u6709 web.xml \u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u7684\u89e3\u6790\u5c31\u9700\u8981 Host \u4e86\uff0c\u5982\u679c\u8981\u6709\u591a\u4e2a Host \u5c31\u8981\u5b9a\u4e49\u4e00\u4e2a top \u5bb9\u5668 Engine \u4e86\u3002\u800c Engine \u6ca1\u6709\u7236\u5bb9\u5668\u4e86\uff0c\u4e00\u4e2a Engine \u4ee3\u8868\u4e00\u4e2a\u5b8c\u6574\u7684 Servlet \u5f15\u64ce\u3002<\/p>\n

          1\u3001Engine \u5bb9\u5668<\/ol>\n
            Engine \u5bb9\u5668\u6bd4\u8f83\u7b80\u5355\uff0c\u5b83\u53ea\u5b9a\u4e49\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u5173\u8054\u5173\u7cfb<\/ol>\n
              2\u3001Host \u5bb9\u5668<\/ol>\n
                Host \u662f Engine \u7684\u5b57\u5bb9\u5668\uff0c\u4e00\u4e2a Host \u5728 Engine \u4e2d\u4ee3\u8868\u4e00\u4e2a\u865a\u62df\u4e3b\u673a\uff0c\u8fd9\u4e2a\u865a\u62df\u4e3b\u673a\u7684\u4f5c\u7528\u5c31\u662f\u8fd0\u884c\u591a\u4e2a\u5e94\u7528\uff0c\u5b83\u8d1f\u8d23\u5b89\u88c5\u548c\u5c55\u5f00\u8fd9\u4e9b\u5e94\u7528\uff0c\u5e76\u4e14\u6807\u8bc6\u8fd9\u4e2a\u5e94\u7528\u4ee5\u4fbf\u80fd\u591f\u533a\u5206\u5b83\u4eec\u3002\u5b83\u7684\u5b50\u5bb9\u5668\u901a\u5e38\u662f Context\uff0c\u5b83\u9664\u4e86\u5173\u8054\u5b50\u5bb9\u5668\u5916\uff0c\u8fd8\u6709\u5c31\u662f\u4fdd\u5b58\u4e00\u4e2a\u4e3b\u673a\u5e94\u8be5\u6709\u7684\u4fe1\u606f\u3002<\/ol>\n
                  3\u3001Context \u5bb9\u5668<\/ol>\n
                    Context \u4ee3\u8868 Servlet \u7684 Context\uff0c\u5b83\u5177\u5907\u4e86 Servlet \u8fd0\u884c\u7684\u57fa\u672c\u73af\u5883\uff0c\u7406\u8bba\u4e0a\u53ea\u8981\u6709 Context \u5c31\u80fd\u8fd0\u884c Servlet \u4e86\u3002\u7b80\u5355\u7684 Tomcat \u53ef\u4ee5\u6ca1\u6709 Engine \u548c Host\u3002Context \u6700\u91cd\u8981\u7684\u529f\u80fd\u5c31\u662f\u7ba1\u7406\u5b83\u91cc\u9762\u7684 Servlet \u5b9e\u4f8b\uff0cServlet \u5b9e\u4f8b\u5728 Context \u4e2d\u662f\u4ee5 Wrapper \u51fa\u73b0\u7684\uff0c\u8fd8\u6709\u4e00\u70b9\u5c31\u662f Context \u5982\u4f55\u624d\u80fd\u627e\u5230\u6b63\u786e\u7684 Servlet \u6765\u6267\u884c\u5b83\u5462? Tomcat5 \u4ee5\u524d\u662f\u901a\u8fc7\u4e00\u4e2a Mapper \u7c7b\u6765\u7ba1\u7406\u7684\uff0cTomcat5 \u4ee5\u540e\u8fd9\u4e2a\u529f\u80fd\u88ab\u79fb\u5230\u4e86 request \u4e2d\uff0c\u5728\u524d\u9762\u7684\u65f6\u5e8f\u56fe\u4e2d\u5c31\u53ef\u4ee5\u53d1\u73b0\u83b7\u53d6\u5b50\u5bb9\u5668\u90fd\u662f\u901a\u8fc7 request \u6765\u5206\u914d\u7684\u3002<\/ol>\n
                      4\u3001Wrapper \u5bb9\u5668<\/ol>\n
                        Wrapper \u4ee3\u8868\u4e00\u4e2a Servlet\uff0c\u5b83\u8d1f\u8d23\u7ba1\u7406\u4e00\u4e2a Servlet\uff0c\u5305\u62ec\u7684 Servlet \u7684\u88c5\u8f7d\u3001\u521d\u59cb\u5316\u3001\u6267\u884c\u4ee5\u53ca\u8d44\u6e90\u56de\u6536\u3002Wrapper \u662f\u6700\u5e95\u5c42\u7684\u5bb9\u5668\uff0c\u5b83\u6ca1\u6709\u5b50\u5bb9\u5668\u4e86\uff0c\u6240\u4ee5\u8c03\u7528\u5b83\u7684 addChild \u5c06\u4f1a\u62a5\u9519\u3002<\/ol>\n
                          Wrapper \u7684\u5b9e\u73b0\u7c7b\u662f StandardWrapper\uff0cStandardWrapper \u8fd8\u5b9e\u73b0\u4e86\u62e5\u6709\u4e00\u4e2a Servlet \u521d\u59cb\u5316\u4fe1\u606f\u7684 ServletConfig\uff0c\u7531\u6b64\u770b\u51fa StandardWrapper \u5c06\u76f4\u63a5\u548c Servlet \u7684\u5404\u79cd\u4fe1\u606f\u6253\u4ea4\u9053\u3002<\/ol>\n
                          Tomcat \u4e2d\u5176\u5b83\u7ec4\u4ef6<\/strong><\/span><\/div>\n

                          Tomcat \u8fd8\u6709\u5176\u5b83\u91cd\u8981\u7684\u7ec4\u4ef6\uff0c\u5982\u5b89\u5168\u7ec4\u4ef6 security\u3001logger \u65e5\u5fd7\u7ec4\u4ef6\u3001session\u3001mbeans\u3001naming \u7b49\u5176\u5b83\u7ec4\u4ef6\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u5171\u540c\u4e3a Connector \u548c Container \u63d0\u4f9b\u5fc5\u8981\u7684\u670d\u52a1\u3002<\/p>\n

                          Tomcat Server\u5904\u7406\u4e00\u4e2aHTTP\u8bf7\u6c42\u7684\u8fc7\u7a0b\uff1a
                          \n\"\"<\/p>\n

                          1\u3001\u7528\u6237\u70b9\u51fb\u7f51\u9875\u5185\u5bb9\uff0c\u8bf7\u6c42\u88ab\u53d1\u9001\u5230\u672c\u673a\u7aef\u53e38080\uff0c\u88ab\u5728\u90a3\u91cc\u76d1\u542c\u7684Coyote HTTP\/1.1 Connector\u83b7\u5f97\u3002<\/p>\n

                          2\u3001Connector\u628a\u8be5\u8bf7\u6c42\u4ea4\u7ed9\u5b83\u6240\u5728\u7684Service\u7684Engine\u6765\u5904\u7406\uff0c\u5e76\u7b49\u5f85Engine\u7684\u56de\u5e94\u3002<\/p>\n

                          3\u3001Engine\u83b7\u5f97\u8bf7\u6c42localhost\/test\/index.jsp\uff0c\u5339\u914d\u6240\u6709\u7684\u865a\u62df\u4e3b\u673aHost\u3002<\/p>\n

                          4\u3001Engine\u5339\u914d\u5230\u540d\u4e3alocalhost\u7684Host(\u5373\u4f7f\u5339\u914d\u4e0d\u5230\u4e5f\u628a\u8bf7\u6c42\u4ea4\u7ed9\u8be5Host\u5904\u7406\uff0c\u56e0\u4e3a\u8be5Host\u88ab\u5b9a\u4e49\u4e3a\u8be5Engine\u7684\u9ed8\u8ba4\u4e3b\u673a)\uff0c\u540d\u4e3alocalhost\u7684Host\u83b7\u5f97\u8bf7\u6c42\/test\/index.jsp\uff0c\u5339\u914d\u5b83\u6240\u62e5\u6709\u7684\u6240\u6709\u7684Context\u3002Host\u5339\u914d\u5230\u8def\u5f84\u4e3a\/test\u7684Context(\u5982\u679c\u5339\u914d\u4e0d\u5230\u5c31\u628a\u8be5\u8bf7\u6c42\u4ea4\u7ed9\u8def\u5f84\u540d\u4e3a\u201c \u201d\u7684Context\u53bb\u5904\u7406)\u3002<\/p>\n

                          5\u3001path=\u201c\/test\u201d\u7684Context\u83b7\u5f97\u8bf7\u6c42\/index.jsp\uff0c\u5728\u5b83\u7684mapping table\u4e2d\u5bfb\u627e\u51fa\u5bf9\u5e94\u7684Servlet\u3002Context\u5339\u914d\u5230URL PATTERN\u4e3a*.jsp\u7684Servlet,\u5bf9\u5e94\u4e8eJspServlet\u7c7b\u3002<\/p>\n

                          6\u3001\u6784\u9020HttpServletRequest\u5bf9\u8c61\u548cHttpServletResponse\u5bf9\u8c61\uff0c\u4f5c\u4e3a\u53c2\u6570\u8c03\u7528JspServlet\u7684doGet()\u6216doPost().\u6267\u884c\u4e1a\u52a1\u903b\u8f91\u3001\u6570\u636e\u5b58\u50a8\u7b49\u7a0b\u5e8f\u3002<\/p>\n

                          7\u3001Context\u628a\u6267\u884c\u5b8c\u4e4b\u540e\u7684HttpServletResponse\u5bf9\u8c61\u8fd4\u56de\u7ed9Host\u3002<\/p>\n

                          8\u3001Host\u628aHttpServletResponse\u5bf9\u8c61\u8fd4\u56de\u7ed9Engine\u3002<\/p>\n

                          9\u3001Engine\u628aHttpServletResponse\u5bf9\u8c61\u8fd4\u56deConnector\u3002<\/p>\n

                          10\u3001Connector\u628aHttpServletResponse\u5bf9\u8c61\u8fd4\u56de\u7ed9\u5ba2\u6237Browser\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

                          Tomcat\u662f\u4e00\u4e2a\u57fa\u4e8e\u7ec4\u4ef6\u7684\u670d\u52a1\u5668\uff0c\u5b83\u7684\u6784\u6210\u7ec4\u4ef6\u90fd\u662f\u53ef\u914d\u7f6e\u7684\uff0c\u5176\u4e2d\u6700\u5916\u5c42\u7684\u662fCatalina servlet\u5bb9 […]<\/p>\n","protected":false},"author":1329,"featured_media":191142,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-191125","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\/191125","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=191125"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191125\/revisions"}],"predecessor-version":[{"id":191172,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191125\/revisions\/191172"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/191142"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=191125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=191125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=191125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}