java 请问如何使用 HttpServer 实现一个将 hello world 返回到请求的服务器中?

使用 HttpServer 实现一个将 hello world 返回到 http://localhost:9000/hello 请求的服务器

当客户端收到 http://localhost:9000/hello 的请求时,请问如何将hello world返回给客户端并打印出来?

用HttpServer.create(new InetSocketAddress(HOSTNAME, PORT), BACKLOG) 创建服务器实例,使用server.createContext设置服务器上下文路径和处理程序

上下文路径使用 hello。
ResponseHeaders设置为Handler,ResponseBody 设置为 write
输入以StandardCharsets.UTF_8编码的byte[]类型的hello world作为write的参数

你可以参考一下这个案例
https://blog.csdn.net/xiaolenglala/article/details/102965011