我尝试将HTML表单数据发送到Java Vertx Verticle,但我将null
作为值。
这是我的代码:
public void start(Future<Void> startFuture) throws Exception {
Router router = Router.router(vertx);
router.route("/html/*").handler(StaticHandler.create().setWebRoot("html/"));
router.route("/html/*").handler(StaticHandler.create().setWebRoot("web/html"));
router.route("/js/*").handler(StaticHandler.create().setWebRoot("web/js"));
router.route("/css/*").handler(StaticHandler.create().setWebRoot("web/css"));
router.route("/fonts/*").handler(StaticHandler.create().setWebRoot("web/fonts"));
Route route = router.route(HttpMethod.POST, "/crypt/testForm/");
route.handler(routingContext -> {
String productType = routingContext.request().getParam("test");
System.out.println(productType);
});
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8085, "localhost", res -> {
if (res.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(res.cause());
}
});
}
对于我的html文件:
<form action="/crypt/testForm" method="post">
<input type ="text" id="test" name ="test"/>
<input type="submit"/>
</form>
问候。
答案 0 :(得分:-1)
这是我的解决方案,也许有帮助,
public void start() throws Exception {
Router router = Router.router(vertx);
router.route("/html/*").handler(StaticHandler.create().setWebRoot("html/"));
router.route("/html/*").handler(StaticHandler.create().setWebRoot("web/html"));
router.route("/js/*").handler(StaticHandler.create().setWebRoot("web/js"));
router.route("/css/*").handler(StaticHandler.create().setWebRoot("web/css"));
router.route("/fonts/*").handler(StaticHandler.create().setWebRoot("web/fonts"));
router.route("/crypt/test").handler(BodyHandler.create());
router.post("/crypt/test").handler(ctx -> {
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
JsonArray js = new JsonArray();
js.add(1);
js.add(5);
js.add(3);
ctx.response().end(js.toString());
});
vertx.createHttpServer().requestHandler(router::accept).listen(8085);
}