Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get POST parameter in JAX-RS method?

People also ask

How do you access parameters in a rested POST method?

You can using the @HeaderParam annotation if you want to pass parameters via HTTP headers: @POST @Path("/create") public void create(@HeaderParam("param1") String param1, @HeaderParam("param2") String param2) { ... }

What is the role of @path in JAX-RS API?

The @Path annotation's value is a partial URI path template relative to the base URI of the server on which the resource is deployed, the context root of the application, and the URL pattern to which the JAX-RS runtime responds.


In a form submitted via POST, email is not a @QueryParam like in /[email protected].

If you submit your HTML form via POST, email is a @FormParam.

Edit:

This is a minimal JAX-RS Resource that can deal with your HTML form.

package rest;

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/console")
public class Console {

    @POST
    @Path("/sendemail")
    @Produces(MediaType.TEXT_PLAIN)
    public Response sendEmail(@FormParam("email") String email) {
        System.out.println(email);
        return Response.ok("email=" + email).build();
    }
}

Just to note one small detail - every input value you want to submit as part of your form has to have "name" attribute.

<input type="text" id="email" name="email" />