How do I read POST parameters for a RESTful service using Jersey?

前端 未结 4 728
南方客
南方客 2020-12-16 10:35

I am not using JSON or anything like that. I have a simple form to upload a file and I want to read the parameters of the form. The code below is not working as expected.

4条回答
  •  再見小時候
    2020-12-16 11:12

    If you are using Jersey RESTful API in JAVA you can look for Parameter Annotations (@*Param)

    Example:

    Dependency:

    
        com.sun.jersey
        jersey-client
        1.8
    
    

    Code:

    package yourpack;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.core.Response;
    
    @Path("/path_to_data")
    public class DataResource {
        @GET
        @Path("/{param}")
        public Response getMsg(@PathParam("param") String urlparam) {
            int ok = 200;
            String result = "Jersey Data resource: " + urlparam;
    
            return Response.status(ok).entity(result ).build();
        }
    }
    

    List of annotations: @MatrixParam, @HeaderParam, @CookieParam, @FormParam, @QueryParam, @PathParam

提交回复
热议问题