Chapter 9. @FormParam
When the input request body is of the type
application/x-www-form-urlencoded
(that is, an HTML form), you can inject individual form parameters from the request body into method parameter values.
<form method="POST" action="/resources/service"> First name: <input type="text" name="firstname"> <br> Last name: <input type="text" name="lastname"> </form>
If you post using this form, the service would look as follows:
@Path("/") public class NameRegistry { @Path("/resources/service") @POST public void addName(@FormParam("firstname") String first, @FormParam("lastname") String last) {...}
You cannot combine
@FormParam
with the default application/x-www-form-urlencoded
that unmarshalls to a MultivaluedMap<String, String>
That is, the following would be illegal:
@Path("/") public class NameRegistry { @Path("/resources/service") @POST @Consumes("application/x-www-form-urlencoded") public void addName(@FormParam("firstname") String first, MultivaluedMap<String, String> form) {...}