{"id":2363,"date":"2024-11-10T09:55:21","date_gmt":"2024-11-10T01:55:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2363\/"},"modified":"2024-11-10T09:55:21","modified_gmt":"2024-11-10T01:55:21","slug":"jsp%e9%a1%b5%e9%9d%a2%e5%bc%95%e7%94%a8js%e6%96%87%e4%bb%b6%e6%97%b6%ef%bc%8c%e5%87%ba%e7%8e%b0404%e9%94%99%e8%af%af%ef%bc%8c%e8%af%a5%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2363\/","title":{"rendered":"JSP\u9875\u9762\u5f15\u7528JS\u6587\u4ef6\u65f6\uff0c\u51fa\u73b0404\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173072054667601.jpg\" class=\"aligncenter\" title=\"JSP\u9875\u9762\u5f15\u7528JS\u6587\u4ef6\u65f6\uff0c\u51fa\u73b0404\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"JSP\u9875\u9762\u5f15\u7528JS\u6587\u4ef6\u65f6\uff0c\u51fa\u73b0404\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jsp\u5f15\u7528js\u6587\u4ef6\u8def\u5f84404\u9519\u8bef\u89e3\u51b3<\/strong><\/p>\n<p>\u5728jsp\u9875\u9762\u5f15\u7528js\u6587\u4ef6\u65f6\uff0c\u4f7f\u7528\u8def\u5f84\u4f1a\u5bfc\u81f4404\u9519\u8bef\uff0c\u539f\u56e0\u5728\u4e8e\uff1a<\/p>\n<ol>\n<li> <strong>\u8def\u5f84\u4e0d\u5b8c\u6574\uff1a<\/strong>request.getContextPath()\u4ec5\u83b7\u53d6\u9879\u76ee\u540d\uff0c\u672a\u5305\u542b\u5b9e\u9645\u90e8\u7f72\u8def\u5f84\uff0c\u56e0\u6b64\u62fc\u63a5\u51fa\u7684\u8def\u5f84\u4e0d\u5b8c\u6574\u3002<\/li>\n<\/ol>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u4fee\u6539\u8def\u5f84\u4e3a\u6839\u76ee\u5f55\uff1a<\/strong>\u5c06\u8def\u5f84\u76f4\u63a5\u5199\u4e3a\/WEB-INF\/resources\/js\/xx.js\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u8def\u5f84\u5b8c\u6574\u6027\u3002<\/li>\n<li> <strong>\u68c0\u67e5request.getContextPath()\u7684\u503c\uff1a<\/strong>\u8f93\u51farequest.getContextPath()\u7684\u503c\uff0c\u67e5\u770b\u662f\u5426\u6709\u62fc\u5199\u9519\u8bef\u6216\u5176\u4ed6\u95ee\u9898\u3002<\/li>\n<li> <strong>\u786e\u8ba4js\u6587\u4ef6\u4f4d\u7f6e\uff1a<\/strong>\u786e\u4fddjs\u6587\u4ef6\u7684\u786e\u4f4d\u4e8e\/resources\/js\u6587\u4ef6\u5939\u4e0b\u3002<\/li>\n<\/ul>\n<p>\u4e00\u822c\u800c\u8a00\uff0cjs\u6587\u4ef6\u90fd\u4f1a\u653e\u7f6e\u5728webapp\u4e0b\uff0c\u4f46\u5982\u679c\u7279\u6b8a\u539f\u56e0\u653e\u5728WEB-INF\u6587\u4ef6\u5939\u4e0b\uff0c\u5219\u9700\u8981\u4f7f\u7528\u6839\u76ee\u5f55\u8def\u5f84\u6216\u5b8c\u6574\u8def\u5f84\u8fdb\u884c\u5f15\u7528\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJSP\u9875\u9762\u5f15\u7528JS\u6587\u4ef6\u65f6\uff0c\u51fa\u73b0404\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jsp\u5f15\u7528js\u6587\u4ef6\u8def\u5f84404\u9519\u8bef\u89e3\u51b3 \u5728jsp\u9875\u9762\u5f15\u7528js\u6587\u4ef6\u65f6\uff0c\u4f7f\u7528\u8def\u5f84\u4f1a\u5bfc\u81f4404\u9519\u8bef\uff0c\u539f\u56e0\u5728\u4e8e\uff1a \u8def\u5f84\u4e0d\u5b8c\u6574\uff1arequest.getContextPath()\u4ec5\u83b7\u53d6\u9879\u76ee\u540d\uff0c\u672a\u5305\u542b\u5b9e\u9645\u90e8\u7f72\u8def\u5f84\uff0c\u56e0\u6b64\u62fc\u63a5\u51fa\u7684\u8def\u5f84\u4e0d\u5b8c\u6574\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u4fee\u6539\u8def\u5f84\u4e3a\u6839\u76ee\u5f55\uff1a\u5c06\u8def\u5f84\u76f4\u63a5\u5199\u4e3a\/WEB-INF\/resources\/js\/xx.js\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u8def\u5f84\u5b8c\u6574\u6027\u3002 \u68c0\u67e5request.getContextPath()\u7684\u503c\uff1a\u8f93\u51farequest.getContextPath()\u7684\u503c\uff0c\u67e5\u770b\u662f\u5426\u6709\u62fc\u5199\u9519\u8bef\u6216\u5176\u4ed6\u95ee\u9898\u3002 \u786e\u8ba4js\u6587\u4ef6\u4f4d\u7f6e\uff1a\u786e\u4fddjs\u6587\u4ef6\u7684\u786e\u4f4d\u4e8e\/resources\/js\u6587\u4ef6\u5939\u4e0b\u3002 \u4e00\u822c\u800c\u8a00\uff0cjs\u6587\u4ef6\u90fd\u4f1a\u653e\u7f6e\u5728webapp\u4e0b\uff0c\u4f46\u5982\u679c\u7279\u6b8a\u539f\u56e0\u653e\u5728WEB-INF\u6587\u4ef6\u5939\u4e0b\uff0c\u5219\u9700\u8981\u4f7f\u7528\u6839\u76ee\u5f55\u8def\u5f84\u6216\u5b8c\u6574\u8def\u5f84\u8fdb\u884c\u5f15\u7528\u3002 \u4ee5\u4e0a\u5c31\u662fJSP\u9875\u9762\u5f15\u7528JS\u6587\u4ef6\u65f6\uff0c\u51fa\u73b0404\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2363","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2363"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2363\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}