Tags

, ,


In this tutorial, we will learn how to submit form to a RESTFul Web Service (JAX-RS).

Resolve Dependency

Include & configure any of the Jax-RS provider e.g Jersey, RESTEasy etc.

HTML Form

<form action="rest/FormSubmitSample" method="post" 
      enctype="application/x-www-form-urlencoded">
   <input id="_name" type="text" name="_name" />
   <input type="submit" />
</form>

Enable JAX-RS Service

@javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends javax.ws.rs.core.Application {
}

JAX-RS Form Submit Service

 @Path("FormSubmitSample")
public class FormSubmitSample {
    @Produces(MediaType.TEXT_PLAIN)
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @POST
    public String addPost(@FormParam("_name") String name) {
        return "Hello "+name;
    }
}
Advertisements