mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add Handler
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package cn.hutool.http.server;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.http.server.handler.RootHandler;
|
||||
|
||||
public class SimpleServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
HttpUtil.createServer(8888)
|
||||
.addHandler("/", new RootHandler("D:\\test"))
|
||||
.start();
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package cn.hutool.http.test;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import cn.hutool.http.server.SimpleServer;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class SimpleServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final SimpleServer server = new SimpleServer(8888);
|
||||
server.addHandler("/", httpExchange -> {
|
||||
httpExchange.sendResponseHeaders(HttpStatus.HTTP_OK, 0);
|
||||
final OutputStream out = httpExchange.getResponseBody();
|
||||
out.write(StrUtil.bytes("Hello Hutool Server!"));
|
||||
IoUtil.close(out);
|
||||
}).start();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user