zoukankan      html  css  js  c++  java
  • vertx 获取请求参数

        表单登录(GET)

    1.  
      <form action="/login">
    2.  
      <input type="text" name="username"/>
    3.  
      <input type="password" name="password"/>
    4.  
      <input type="submit" />
    5.  
      </form>

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

    1.  
      public class LoginHandler implements Handler<RoutingContext> {
    2.  
       
    3.  
      public void handle(RoutingContext rc) {
    4.  
       
    5.  
      String username = rc.request().getParam("username");
    6.  
      String password = rc.request().getParam("password");
    7.  
       
    8.  
      System.out.println(username + "-->" + password);
    9.  
       
    10.  
      rc.next();
    11.  
      }
    12.  
      }

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

    1.  
      public class LoginHandler implements Handler<RoutingContext> {
    2.  
       
    3.  
      public void handle(RoutingContext rc) {
    4.  
       
    5.  
      rc.request().setExpectMultipart(true);
    6.  
      rc.request().endHandler(end -> {
    7.  
       
    8.  
      String username = rc.request().formAttributes().get("username");
    9.  
      String password = rc.request().formAttributes().get("password");
    10.  
       
    11.  
      System.out.println(username + "-->" + password);
    12.  
       
    13.  
      rc.next();
    14.  
      });
    15.  
      }
    16.  
      }
     
     
  • 相关阅读:
    剑指Offer--反转链表
    剑指Offer--链表中倒数第k个结点
    面向对象的六原则一法则
    常见错误汇总
    记人生第一次CF体验
    Game of Credit Cards
    Shell Game (模拟)
    数列分块入门 1 LibreOJ
    范德蒙恒等式
    C. Vasya and String (尺取法)
  • 原文地址:https://www.cnblogs.com/exmyth/p/14207271.html
Copyright © 2011-2022 走看看