Forms and beans
A nice feature of JAX-RS is the interactions with the web forms. The parameters of a form that point to a REST service can be automatically imported in the service without too much code to write. Take a look at this simple HTML form code:
<html> <body> <h1>JAX-RS @FormParam Example</h1> <formaction="myjaxrs/simple/form"method="post"> <labelfor="data">Data: </label> <inputid="data"type="text" name="data"/> <inputtype="submit"value="Submit"/> </form> </body> </html>
This form points to the myjaxrs/simple/form
REST service represented by the service:
@Path("/simple") @Stateless publicclass SimpleService { ... @POST @Path("form") @Produces(TEXT_HTML) public String values(@FormParam("data") String data) { returndata; } }
The @FormParam
lets you automatically take the input fields of the form and serialize them in the service as input parameters...