<dependency> <groupId>org.activej</groupId> <artifactId>activej-http</artifactId> <version>4.0.2</version> </dependency> import io.activej.http.HttpResponse; import io.activej.http.RoutingServlet; import io.activej.http.loader.StaticLoader; import static io.activej.http.HttpMethod.GET; ... public class MyHttpServer { public static void main(String[] args) throws Exception { HttpServer server = HttpServer.create() .withHandler(RoutingServlet.create() .map(GET, "/", request -> HttpResponse.ok200().withPlainText("Hello, World!")) .map(GET, "/users", request -> HttpResponse.ok200().withPlainText("User list"))) .withStaticServe("/static", StaticLoader.ofClassPathResources(MyHttpServer.class, "/static")); server.listenAndServe(8080); } }


上一篇:
下一篇:
切换中文