How to access POST parameters in HttpServletRequest?

前端 未结 1 708
鱼传尺愫
鱼传尺愫 2021-01-21 04:12

I\'ve got an app that\'s basically a proxy to a service. The app itself is built on Jersey and served by Jetty. I have this Resource method:

@POST
@Path(\"/{defa         


        
1条回答
  •  伪装坚强ぢ
    2021-01-21 04:42

    Three options

    1. @FormParam("") to gt individual params. Ex.

      @POST
      @Consumes("application/x-www-form-urlencoded")
      public Response post(@FormParam("foo") String foo
                           @FormParam("bar") String bar) {}
      
    2. Use a MultivaluedMap to get all the params

      @POST
      @Consumes("application/x-www-form-urlencoded")
      public Response post(MultivaluedMap formParams) {
          String foo = formParams.getFirst("foo");
      }
      
    3. Use Form to get all the params.

      @POST
      @Consumes("application/x-www-form-urlencoded")
      public Response post(Form form) {
          MultivaluedMap formParams = form.asMap();
          String foo = formParams.getFirst("foo");
      }
      
    4. Use a @BeanParam along with individual @FormParams to get all the individual params inside a bean.

      public class FormBean {
          @FormParam("foo")
          private String foo;
          @FormParam("bar")
          private String bar;
          // getters and setters
      }
      
      @POST
      @Consumes("application/x-www-form-urlencoded")
      public Response post(@BeanParam FormBean form) {
      }
      

    0 讨论(0)
提交回复
热议问题