返回 字符串的 form和js组合让页面跳转

        router.get("/wy/jhy").handler(ctx->{
            ctx.request().response().setChunked(true);
            System.out.println("到此..........................................................................");

            ctx.request().params().names().stream().forEach(name->{
                System.out.println("******************************************-:-"+name);
            });
            System.out.println(ctx.request().getParam("merOrderId"));

            String merOrderId = ctx.request().getParam("merOrderId");
            String last = merOrderId.substring(5);
            String tenantOrderNo = last.substring(0, last.length() - 19);
            String tenantId = last.substring(tenantOrderNo.length());

            JsonObject toDBRead = new JsonObject();
            toDBRead.put("read_or_write", "read");
            toDBRead.put("sql", MybatisNamespace.orders_getSy);

            JsonObject params = new JsonObject();
            params.put("tenantId",tenantId);
            params.put("tenantOrderNo",tenantOrderNo);

            toDBRead.put("params", params.toString());

            vertx.eventBus().<String>send(DB_CENTER_ADDRESS, toDBRead.toString(), new DeliveryOptions().setSendTimeout(60000), result -> {
                if (result.succeeded()) {

                    System.out.println("=== : "+result.result().body());

                    String amount = ctx.request().getParam("amount");
                    StringBuilder sb = new StringBuilder(amount);
                    sb.insert(amount.length() - 2, ".");

                    String form = "<form id=\"returnForm\" action=\""+result.result().body()+"\" method=\"get\">\n" +
                            "<input type=\"hidden\" name=\"amount\" value=\""+sb.toString()+"\"/>\n" +
                            "<input type=\"hidden\" name=\"tenantId\" value=\""+tenantId+"\"/>\n" +
                            "<input type=\"hidden\" name=\"tenantOrderNo\" value=\""+tenantOrderNo+"\"/>\n" +
                            "</form>\n" +
                            "<script>document.getElementById(\"returnForm\").submit();</script>";
                    ctx.request().response().putHeader("Content-Type","text/html;charset=utf-8");
                    ctx.request().response().setStatusCode(200).write(form).end();
                } else {
                    ctx.request().response().putHeader("Content-Type","text/html;charset=utf-8");
                    ctx.request().response().setStatusCode(200).end("内部错误");
                }
            });

        });
<form id="returnForm" action="http://www.baidu.com" method="get">
<input type="hidden" name="amount" value="11.00"/>
<input type="hidden" name="tenantId" value="4778638114955493397"/>
<input type="hidden" name="tenantOrderNo" value="6CGeIhuL0apDX0aO03Ntd6lT"/>
</form>
<script>document.getElementById("returnForm").submit();</script>

vertx 代码示例

posted on 2018-06-07 17:43  --LP--  阅读(295)  评论(0编辑  收藏  举报

导航