Creating a RESTful web service with form POST

We have created RESTful web services so far with HTTP GET and POST methods. The web service using the POST method took input in the JSON format. We can also have the POST method in the web service take input from HTML form elements. Let's create a method that handles the data posted from a HTML form. Open CourseService.java from the CourseManagementREST project. Add the following method:

@POST 
@Consumes (MediaType.APPLICATION_FORM_URLENCODED) 
@Path("add") 
public Response addCourseFromForm (@FormParam("name") String courseName, 
    @FormParam("credits") int credits) throws URISyntaxException { 
 
  dummyAddCourse(courseName, credits); 
 
  return Response.seeOther(new  URI("../addCourseSuccess.html")).build(); ...

Get Java EE 8 Development with Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.