我正在写一个vertx.io网络服务器,我正在尝试创建一个简单的网络响应,包括一个网页。我已设法发送index.html,显示。如何添加其他文件,例如JavaScript和CSS文件,以便显示完整的网页?或者最好发送一次文件,因为它们不会改变。
RouteMatcher routeMatcher = new RouteMatcher().get("/", new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest httpServerRequest) {
httpServerRequest.response().sendFile("src/web/index.html");
}
});
vertx.createHttpServer().requestHandler(routeMatcher).listen(8181, "localhost");
答案 0 :(得分:0)
RouteMatcher httpRouteMatcher = new RouteMatcher().get("/", new
Handler<HttpServerRequest>() {
@Override
public void handle(final HttpServerRequest request) {
request.response().sendFile("web/chat.html");
}
}).get(".*\\.(css|js)$", new Handler<HttpServerRequest>() {
@Override
public void handle(final HttpServerRequest request) {
request.response().sendFile("web/" + new File(request.path()));
}
});