{"id":44432,"date":"2025-06-19T07:15:50","date_gmt":"2025-06-18T23:15:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/44432.html"},"modified":"2025-06-19T07:15:50","modified_gmt":"2025-06-18T23:15:50","slug":"%e5%88%86%e6%9e%90-java-18-%e7%9a%84%e7%ae%80%e5%8d%95-web-%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%88simple-web-server%ef%bc%89-2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/44432.html","title":{"rendered":"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E8%AE%BE%E8%AE%A1%E8%83%8C%E6%99%AF%E4%B8%8E%E6%A0%B8%E5%BF%83%E7%9B%AE%E6%A0%87-toc\" style=\"margin-left:80px\">\u4e00\u3001\u8bbe\u8ba1\u80cc\u666f\u4e0e\u6838\u5fc3\u76ee\u6807<\/p>\n<p id=\"1.%20%E7%97%9B%E7%82%B9%E4%B8%8E%E9%9C%80%E6%B1%82-toc\" style=\"margin-left:120px\">1. \u75db\u70b9\u4e0e\u9700\u6c42<\/p>\n<p id=\"2.%20JEP%20408%20%E7%9A%84%E5%AE%9A%E4%BD%8D-toc\" style=\"margin-left:120px\">2. JEP 408 \u7684\u5b9a\u4f4d<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E6%A0%B8%E5%BF%83%E5%8A%9F%E8%83%BD%E4%B8%8E%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F-toc\" style=\"margin-left:80px\">\u4e8c\u3001\u6838\u5fc3\u529f\u80fd\u4e0e\u4f7f\u7528\u65b9\u5f0f<\/p>\n<p id=\"1.%20%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%90%AF%E5%8A%A8%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89-toc\" style=\"margin-left:120px\">1. \u547d\u4ee4\u884c\u542f\u52a8&#xff08;\u63a8\u8350&#xff09;<\/p>\n<p id=\"2.%20%E7%BC%96%E7%A8%8B%E5%BC%8F%20API-toc\" style=\"margin-left:120px\">2. \u7f16\u7a0b\u5f0f API<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E6%8A%80%E6%9C%AF%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3-toc\" style=\"margin-left:80px\">\u4e09\u3001\u6280\u672f\u7279\u6027\u8be6\u89e3<\/p>\n<p id=\"1.%20HTTP%20%E5%8D%8F%E8%AE%AE%E6%94%AF%E6%8C%81-toc\" style=\"margin-left:120px\">1. HTTP \u534f\u8bae\u652f\u6301<\/p>\n<p id=\"2.%20%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%9C%8D%E5%8A%A1%E6%9C%BA%E5%88%B6-toc\" style=\"margin-left:120px\">2. \u9759\u6001\u6587\u4ef6\u670d\u52a1\u673a\u5236<\/p>\n<p id=\"3.%20%E6%80%A7%E8%83%BD%E4%B8%8E%E6%89%A9%E5%B1%95%E6%80%A7-toc\" style=\"margin-left:120px\">3. \u6027\u80fd\u4e0e\u6269\u5c55\u6027<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E5%85%B8%E5%9E%8B%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:80px\">\u56db\u3001\u5178\u578b\u5e94\u7528\u573a\u666f<\/p>\n<p id=\"1.%20%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99%E5%BC%80%E5%8F%91-toc\" style=\"margin-left:120px\">1. \u9759\u6001\u7f51\u7ad9\u5f00\u53d1<\/p>\n<p id=\"2.%20API%20%E5%8E%9F%E5%9E%8B%E5%BC%80%E5%8F%91-toc\" style=\"margin-left:120px\">2. API \u539f\u578b\u5f00\u53d1<\/p>\n<p id=\"3.%20%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:120px\">3. \u81ea\u52a8\u5316\u6d4b\u8bd5<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E4%B8%8E%E5%85%B6%E4%BB%96%E5%B7%A5%E5%85%B7%E7%9A%84%E5%AF%B9%E6%AF%94-toc\" style=\"margin-left:80px\">\u4e94\u3001\u4e0e\u5176\u4ed6\u5de5\u5177\u7684\u5bf9\u6bd4<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5%E4%B8%8E%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9-toc\" style=\"margin-left:80px\">\u516d\u3001\u6700\u4f73\u5b9e\u8df5\u4e0e\u6ce8\u610f\u4e8b\u9879<\/p>\n<p id=\"1.%20%E5%AE%89%E5%85%A8%E9%99%90%E5%88%B6-toc\" style=\"margin-left:120px\">1. \u5b89\u5168\u9650\u5236<\/p>\n<p id=\"2.%20%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96-toc\" style=\"margin-left:120px\">2. \u6027\u80fd\u4f18\u5316<\/p>\n<p id=\"3.%20%E6%89%A9%E5%B1%95%E8%87%AA%E5%AE%9A%E4%B9%89-toc\" style=\"margin-left:120px\">3. \u6269\u5c55\u81ea\u5b9a\u4e49<\/p>\n<p id=\"%E4%B8%83%E3%80%81%E6%80%BB%E7%BB%93%E4%B8%8E%E6%9C%AA%E6%9D%A5%E5%B1%95%E6%9C%9B-toc\" style=\"margin-left:80px\">\u4e03\u3001\u603b\u7ed3\u4e0e\u672a\u6765\u5c55\u671b<\/p>\n<hr id=\"hr-toc\" \/>\n<h4 id=\"%E4%B8%80%E3%80%81%E8%AE%BE%E8%AE%A1%E8%83%8C%E6%99%AF%E4%B8%8E%E6%A0%B8%E5%BF%83%E7%9B%AE%E6%A0%87\">\u4e00\u3001\u8bbe\u8ba1\u80cc\u666f\u4e0e\u6838\u5fc3\u76ee\u6807<\/h4>\n<h5 id=\"1.%20%E7%97%9B%E7%82%B9%E4%B8%8E%E9%9C%80%E6%B1%82\">1. \u75db\u70b9\u4e0e\u9700\u6c42<\/h5>\n<ul>\n<li>\u5f00\u53d1\u6548\u7387&#xff1a;\u4f20\u7edf Web \u670d\u52a1\u5668&#xff08;\u5982 Tomcat\u3001Jetty&#xff09;\u914d\u7f6e\u590d\u6742&#xff0c;\u542f\u52a8\u7f13\u6162&#xff0c;\u4e0d\u9002\u5408\u5feb\u901f\u539f\u578b\u5f00\u53d1\u3002<\/li>\n<li>\u6559\u5b66\u95e8\u69db&#xff1a;Java \u521d\u5b66\u8005\u9700\u638c\u63e1\u590d\u6742\u6846\u67b6\u624d\u80fd\u642d\u5efa\u7b80\u5355 HTTP \u670d\u52a1\u3002<\/li>\n<li>\u4e34\u65f6\u6587\u4ef6\u5171\u4eab&#xff1a;\u7f3a\u4e4f\u7c7b\u4f3c Python\u00a0http.server\u00a0\u7684\u8f7b\u91cf\u7ea7\u5de5\u5177\u3002<\/li>\n<\/ul>\n<h5 id=\"2.%20JEP%20408%20%E7%9A%84%E5%AE%9A%E4%BD%8D\">2. JEP 408 \u7684\u5b9a\u4f4d<\/h5>\n<p>Java 18 \u5f15\u5165\u7684\u00a0Simple Web Server\u00a0\u65e8\u5728\u63d0\u4f9b\u00a0\u96f6\u914d\u7f6e\u3001\u5f00\u7bb1\u5373\u7528\u00a0\u7684 HTTP \u670d\u52a1\u5668&#xff0c;\u6838\u5fc3\u7279\u6027\u5305\u62ec&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u9759\u6001\u6587\u4ef6\u670d\u52a1&#xff1a;\u5feb\u901f\u6258\u7ba1 HTML\u3001CSS\u3001JS \u7b49\u9759\u6001\u8d44\u6e90\u3002<\/li>\n<li>\u6781\u7b80 API&#xff1a;\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u5c11\u91cf\u4ee3\u7801\u5373\u53ef\u542f\u52a8\u670d\u52a1\u5668\u3002<\/li>\n<li>\u8f7b\u91cf\u7ea7\u8bbe\u8ba1&#xff1a;\u57fa\u4e8e JDK \u5185\u7f6e\u7ec4\u4ef6&#xff0c;\u65e0\u9700\u989d\u5916\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n<h4 id=\"%E4%BA%8C%E3%80%81%E6%A0%B8%E5%BF%83%E5%8A%9F%E8%83%BD%E4%B8%8E%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F\">\u4e8c\u3001\u6838\u5fc3\u529f\u80fd\u4e0e\u4f7f\u7528\u65b9\u5f0f<\/h4>\n<h5 id=\"1.%20%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%90%AF%E5%8A%A8%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89\">1. \u547d\u4ee4\u884c\u542f\u52a8&#xff08;\u63a8\u8350&#xff09;<\/h5>\n<p># \u9ed8\u8ba4\u542f\u52a8&#xff1a;\u76d1\u542c 8000 \u7aef\u53e3&#xff0c;\u670d\u52a1\u5f53\u524d\u76ee\u5f55<br \/>\njwebserver<\/p>\n<p># \u81ea\u5b9a\u4e49\u7aef\u53e3\u548c\u76ee\u5f55<br \/>\njwebserver -p 8080 -d \/path\/to\/public\/files<\/p>\n<p># \u7ed1\u5b9a\u6240\u6709\u7f51\u7edc\u63a5\u53e3&#xff08;\u652f\u6301\u5c40\u57df\u7f51\u8bbf\u95ee&#xff09;<br \/>\njwebserver -b 0.0.0.0<\/p>\n<p># \u8be6\u7ec6\u65e5\u5fd7\u6a21\u5f0f<br \/>\njwebserver -o verbose<\/p>\n<h5 id=\"2.%20%E7%BC%96%E7%A8%8B%E5%BC%8F%20API\">2. \u7f16\u7a0b\u5f0f API<\/h5>\n<p>import com.sun.net.httpserver.*;<br \/>\nimport java.io.IOException;<br \/>\nimport java.net.InetSocketAddress;<br \/>\nimport java.nio.file.Path;<\/p>\n<p>public class SimpleServerExample {<br \/>\n    public static void main(String[] args) throws IOException {<br \/>\n        \/\/ \u521b\u5efa\u670d\u52a1\u5668&#xff0c;\u76d1\u542c 8080 \u7aef\u53e3&#xff0c;\u670d\u52a1\u6307\u5b9a\u76ee\u5f55<br \/>\n        HttpServer server &#061; SimpleFileServer.createFileServer(<br \/>\n            new InetSocketAddress(8080),<br \/>\n            Path.of(&#034;public&#034;),<br \/>\n            SimpleFileServer.OutputLevel.INFO<br \/>\n        );<\/p>\n<p>        \/\/ \u6dfb\u52a0\u81ea\u5b9a\u4e49\u5904\u7406\u5668&#xff08;\u5904\u7406 \/api \u8def\u5f84&#xff09;<br \/>\n        server.createContext(&#034;\/api\/hello&#034;, exchange -&gt; {<br \/>\n            String response &#061; &#034;Hello from Java 18!&#034;;<br \/>\n            exchange.sendResponseHeaders(200, response.getBytes().length);<br \/>\n            exchange.getResponseBody().write(response.getBytes());<br \/>\n            exchange.close();<br \/>\n        });<\/p>\n<p>        server.start();<br \/>\n        System.out.println(&#034;Server running at http:\/\/localhost:8080&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"%E4%B8%89%E3%80%81%E6%8A%80%E6%9C%AF%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3\">\u4e09\u3001\u6280\u672f\u7279\u6027\u8be6\u89e3<\/h4>\n<h5 id=\"1.%20HTTP%20%E5%8D%8F%E8%AE%AE%E6%94%AF%E6%8C%81\">1. HTTP \u534f\u8bae\u652f\u6301<\/h5>\n<ul>\n<li>\u7248\u672c&#xff1a;\u4ec5\u652f\u6301 HTTP\/1.1&#xff08;\u4e0d\u652f\u6301 HTTP\/2 \u6216 HTTPS&#xff09;\u3002<\/li>\n<li>\u65b9\u6cd5&#xff1a;\u9ed8\u8ba4\u4ec5\u5904\u7406\u00a0GET\u00a0\u548c\u00a0HEAD\u00a0\u8bf7\u6c42\u3002<\/li>\n<li>\u72b6\u6001\u7801&#xff1a;\u81ea\u52a8\u5904\u7406\u5e38\u89c1\u72b6\u6001\u7801&#xff08;\u5982 200\u3001404\u3001500&#xff09;\u3002<\/li>\n<\/ul>\n<h5 id=\"2.%20%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%9C%8D%E5%8A%A1%E6%9C%BA%E5%88%B6\">2. \u9759\u6001\u6587\u4ef6\u670d\u52a1\u673a\u5236<\/h5>\n<ul>\n<li>MIME \u7c7b\u578b\u68c0\u6d4b&#xff1a;\u57fa\u4e8e\u6587\u4ef6\u6269\u5c55\u540d\u81ea\u52a8\u6620\u5c04&#xff08;\u5982\u00a0.html\u00a0\u2192\u00a0text\/html&#xff09;\u3002<\/li>\n<li>\u76ee\u5f55\u5217\u8868&#xff1a;\u8bbf\u95ee\u76ee\u5f55\u65f6\u8fd4\u56de\u6587\u4ef6\u5217\u8868&#xff08;\u53ef\u7981\u7528&#xff09;\u3002<\/li>\n<li>\u7f13\u5b58\u63a7\u5236&#xff1a;\u652f\u6301\u00a0ETag\u00a0\u548c\u00a0Last-Modified\u00a0\u5934&#xff0c;\u4f18\u5316\u5ba2\u6237\u7aef\u7f13\u5b58\u3002<\/li>\n<\/ul>\n<h5 id=\"3.%20%E6%80%A7%E8%83%BD%E4%B8%8E%E6%89%A9%E5%B1%95%E6%80%A7\">3. \u6027\u80fd\u4e0e\u6269\u5c55\u6027<\/h5>\n<ul>\n<li>\u7ebf\u7a0b\u6a21\u578b&#xff1a;\u57fa\u4e8e\u00a0ThreadPoolExecutor&#xff0c;\u9ed8\u8ba4\u7ebf\u7a0b\u6570\u4e3a CPU \u6838\u5fc3\u6570 &#043; 1\u3002<\/li>\n<li>\u9002\u7528\u573a\u666f&#xff1a;\n<ul>\n<li>\u5f00\u53d1\u9636\u6bb5&#xff1a;\u5feb\u901f\u9a8c\u8bc1\u524d\u7aef\u9875\u9762\u6216 API \u539f\u578b\u3002<\/li>\n<li>\u6d4b\u8bd5\u73af\u5883&#xff1a;\u6a21\u62df\u5916\u90e8\u670d\u52a1\u54cd\u5e94\u3002<\/li>\n<li>\u4e34\u65f6\u6587\u4ef6\u5171\u4eab&#xff1a;\u901a\u8fc7\u5c40\u57df\u7f51\u5feb\u901f\u4f20\u8f93\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4 id=\"%E5%9B%9B%E3%80%81%E5%85%B8%E5%9E%8B%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF\">\u56db\u3001\u5178\u578b\u5e94\u7528\u573a\u666f<\/h4>\n<h5 id=\"1.%20%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99%E5%BC%80%E5%8F%91\">1. \u9759\u6001\u7f51\u7ad9\u5f00\u53d1<\/h5>\n<p># \u5feb\u901f\u542f\u52a8\u524d\u7aef\u9879\u76ee<br \/>\ncd my-react-app\/build<br \/>\njwebserver -p 3000<\/p>\n<h5 id=\"2.%20API%20%E5%8E%9F%E5%9E%8B%E5%BC%80%E5%8F%91\">2. API \u539f\u578b\u5f00\u53d1<\/h5>\n<p>server.createContext(&#034;\/api\/users&#034;, exchange -&gt; {<br \/>\n    String response &#061; &#034;&#034;&#034;<br \/>\n        [<br \/>\n            {&#034;id&#034;: 1, &#034;name&#034;: &#034;Alice&#034;},<br \/>\n            {&#034;id&#034;: 2, &#034;name&#034;: &#034;Bob&#034;}<br \/>\n        ]<br \/>\n    &#034;&#034;&#034;;<br \/>\n    exchange.getResponseHeaders().set(&#034;Content-Type&#034;, &#034;application\/json&#034;);<br \/>\n    exchange.sendResponseHeaders(200, response.length());<br \/>\n    exchange.getResponseBody().write(response.getBytes());<br \/>\n});<\/p>\n<h5 id=\"3.%20%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95\">3. \u81ea\u52a8\u5316\u6d4b\u8bd5<\/h5>\n<p>&#064;BeforeAll<br \/>\nstatic void startServer() throws IOException {<br \/>\n    HttpServer server &#061; HttpServer.create(new InetSocketAddress(8080), 0);<br \/>\n    server.createContext(&#034;\/test&#034;, exchange -&gt; {<br \/>\n        exchange.sendResponseHeaders(200, 0);<br \/>\n        exchange.close();<br \/>\n    });<br \/>\n    server.start();<br \/>\n}<\/p>\n<h4 id=\"%E4%BA%94%E3%80%81%E4%B8%8E%E5%85%B6%E4%BB%96%E5%B7%A5%E5%85%B7%E7%9A%84%E5%AF%B9%E6%AF%94\">\u4e94\u3001\u4e0e\u5176\u4ed6\u5de5\u5177\u7684\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\u7279\u6027Simple Web ServerPython http.serverNode.js ExpressTomcat<\/tr>\n<tbody>\n<tr>\n<td>\u542f\u52a8\u901f\u5ea6<\/td>\n<td>\u6781\u5feb&#xff08;\u6beb\u79d2\u7ea7&#xff09;<\/td>\n<td>\u5feb&#xff08;\u79d2\u7ea7&#xff09;<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u6162&#xff08;\u79d2\u7ea7&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u9759\u6001\u6587\u4ef6\u670d\u52a1<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>\u52a8\u6001\u5185\u5bb9\u652f\u6301<\/td>\n<td>\u274c<\/td>\n<td>\u274c<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>HTTPS \u652f\u6301<\/td>\n<td>\u274c<\/td>\n<td>\u274c&#xff08;\u9700\u989d\u5916\u914d\u7f6e&#xff09;<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<tr>\n<td>\u90e8\u7f72\u590d\u6742\u5ea6<\/td>\n<td>\u6781\u4f4e<\/td>\n<td>\u4f4e<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u9ad8<\/td>\n<\/tr>\n<tr>\n<td>\u751f\u4ea7\u73af\u5883\u9002\u7528\u6027<\/td>\n<td>\u274c<\/td>\n<td>\u274c<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"%E5%85%AD%E3%80%81%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5%E4%B8%8E%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9\">\u516d\u3001\u6700\u4f73\u5b9e\u8df5\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h4>\n<h5 id=\"1.%20%E5%AE%89%E5%85%A8%E9%99%90%E5%88%B6\">1. \u5b89\u5168\u9650\u5236<\/h5>\n<ul>\n<li>\u4e0d\u9002\u5408\u751f\u4ea7\u73af\u5883&#xff1a;\u7f3a\u4e4f HTTPS\u3001\u8ba4\u8bc1\u548c\u9632\u653b\u51fb\u673a\u5236\u3002<\/li>\n<li>\u6587\u4ef6\u8bbf\u95ee\u9650\u5236&#xff1a;\u9ed8\u8ba4\u4ec5\u670d\u52a1\u5f53\u524d\u76ee\u5f55\u53ca\u5176\u5b50\u76ee\u5f55&#xff0c;\u907f\u514d\u66b4\u9732\u654f\u611f\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<h5 id=\"2.%20%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96\">2. \u6027\u80fd\u4f18\u5316<\/h5>\n<ul>\n<li>\u9ad8\u5e76\u53d1\u573a\u666f&#xff1a;\u7ed3\u5408 Nginx \u6216 Apache \u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u3002<\/li>\n<li>\u5927\u6587\u4ef6\u4f20\u8f93&#xff1a;\u5229\u7528\u5185\u7f6e\u7684\u6587\u4ef6\u76f4\u63a5\u4f20\u8f93\u673a\u5236&#xff0c;\u51cf\u5c11\u5185\u5b58\u62f7\u8d1d\u3002<\/li>\n<\/ul>\n<h5 id=\"3.%20%E6%89%A9%E5%B1%95%E8%87%AA%E5%AE%9A%E4%B9%89\">3. \u6269\u5c55\u81ea\u5b9a\u4e49<\/h5>\n<ul>\n<li>\u8fc7\u6ee4\u5668\u94fe&#xff1a;\u901a\u8fc7\u00a0HttpFilter\u00a0\u6dfb\u52a0\u65e5\u5fd7\u3001CORS \u652f\u6301\u7b49\u529f\u80fd\u3002<\/li>\n<li>\u8def\u5f84\u6620\u5c04&#xff1a;\u4f7f\u7528\u00a0createContext\u00a0\u65b9\u6cd5\u81ea\u5b9a\u4e49 URL \u8def\u5f84\u5904\u7406\u903b\u8f91\u3002<\/li>\n<\/ul>\n<h4 id=\"%E4%B8%83%E3%80%81%E6%80%BB%E7%BB%93%E4%B8%8E%E6%9C%AA%E6%9D%A5%E5%B1%95%E6%9C%9B\">\u4e03\u3001\u603b\u7ed3\u4e0e\u672a\u6765\u5c55\u671b<\/h4>\n<p>Java 18 \u7684 Simple Web Server \u901a\u8fc7\u00a0\u96f6\u914d\u7f6e\u8bbe\u8ba1\u00a0\u548c\u00a0\u6781\u7b80 API&#xff0c;\u663e\u8457\u63d0\u5347\u4e86\u5f00\u53d1\u6548\u7387&#xff0c;\u5c24\u5176\u9002\u5408&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u524d\u7aef\u5f00\u53d1\u8005\u5feb\u901f\u9a8c\u8bc1\u9875\u9762<\/li>\n<li>\u540e\u7aef\u5f00\u53d1\u8005\u6a21\u62df API \u54cd\u5e94<\/li>\n<li>\u6d4b\u8bd5\u5de5\u7a0b\u5e08\u642d\u5efa\u4e34\u65f6\u670d\u52a1<\/li>\n<\/ul>\n<p>\u672a\u6765\u53ef\u80fd\u7684\u6539\u8fdb\u65b9\u5411&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>HTTPS \u652f\u6301&#xff1a;\u901a\u8fc7 JEP \u589e\u5f3a&#xff0c;\u7b80\u5316\u8bc1\u4e66\u914d\u7f6e\u3002<\/li>\n<li>WebSocket \u96c6\u6210&#xff1a;\u6269\u5c55\u534f\u8bae\u652f\u6301&#xff0c;\u6ee1\u8db3\u5b9e\u65f6\u901a\u4fe1\u9700\u6c42\u3002<\/li>\n<li>\u6a21\u5757\u5316\u8bbe\u8ba1&#xff1a;\u652f\u6301\u63d2\u4ef6\u673a\u5236&#xff0c;\u589e\u5f3a\u529f\u80fd\u6269\u5c55\u6027\u3002<\/li>\n<\/ul>\n<p>\u638c\u63e1\u8fd9\u4e00\u5de5\u5177\u53ef\u5927\u5e45\u51cf\u5c11\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u73af\u5883\u642d\u5efa\u6210\u672c&#xff0c;\u4f7f\u5f00\u53d1\u8005\u66f4\u4e13\u6ce8\u4e8e\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u638c\u63e1\u8fd9\u4e00\u5de5\u5177\u53ef\u5927\u5e45\u51cf\u5c11\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u73af\u5883\u642d\u5efa\u6210\u672c\uff0c\u4f7f\u5f00\u53d1\u8005\u66f4\u4e13\u6ce8\u4e8e\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u3002_java simple web server<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4115,4114,87,43],"topic":[],"class_list":["post-44432","post","type-post","status-publish","format-standard","hentry","category-server","tag-java18","tag-java","tag-87","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/44432.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u638c\u63e1\u8fd9\u4e00\u5de5\u5177\u53ef\u5927\u5e45\u51cf\u5c11\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u73af\u5883\u642d\u5efa\u6210\u672c\uff0c\u4f7f\u5f00\u53d1\u8005\u66f4\u4e13\u6ce8\u4e8e\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u3002_java simple web server\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/44432.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-18T23:15:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44432.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/44432.html\",\"name\":\"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-18T23:15:50+00:00\",\"dateModified\":\"2025-06-18T23:15:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/44432.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/44432.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44432.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/44432.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u638c\u63e1\u8fd9\u4e00\u5de5\u5177\u53ef\u5927\u5e45\u51cf\u5c11\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u73af\u5883\u642d\u5efa\u6210\u672c\uff0c\u4f7f\u5f00\u53d1\u8005\u66f4\u4e13\u6ce8\u4e8e\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u3002_java simple web server","og_url":"https:\/\/www.wsisp.com\/helps\/44432.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-18T23:15:50+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/44432.html","url":"https:\/\/www.wsisp.com\/helps\/44432.html","name":"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-18T23:15:50+00:00","dateModified":"2025-06-18T23:15:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/44432.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/44432.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/44432.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5206\u6790 Java 18 \u7684\u7b80\u5355 Web \u670d\u52a1\u5668\uff08Simple Web Server\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/44432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=44432"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/44432\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=44432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=44432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=44432"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=44432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}