vertx 获取请求参数

    表单登录(GET)

<form action="/login">
    <input type="text" name="username"/>
    <input type="password" name="password"/>
    <input type="submit" />
</form>

使用下面的代码,获取请求的参数没问题:

public class LoginHandler implements Handler<RoutingContext> {

    public void handle(RoutingContext rc) {

        String username = rc.request().getParam("username");
        String password = rc.request().getParam("password");

        System.out.println(username + "-->" + password);

        rc.next();
    }
}

 但是换成POST就得不到了,如果处理POST,需要用下面的方式处理

public class LoginHandler implements Handler<RoutingContext> {

    public void handle(RoutingContext rc) {

        rc.request().setExpectMultipart(true);
        rc.request().endHandler(end -> {

            String username = rc.request().formAttributes().get("username");
            String password = rc.request().formAttributes().get("password");

            System.out.println(username + "-->" + password);

            rc.next();
        });
    }
}

猜你喜欢

转载自xiaojianhx.iteye.com/blog/2348029