JAX-RS - @PUT with JQuery Example

[Last Updated: Aug 29, 2018]

HTML form only supports GET and POST. To use other HTTP Methods from a web browser, we can use JavaScript Ajax call. In this example we are using JQuery API.

Here's how an HTML Form along with JQuery can be used to make a PUT (and other HTTP methods) request.

           //disable default form submission
            var $form = $(this);

                type : 'PUT',
                url : url,
                contentType: 'application/json',
                data : form_data//should be converted fo json

                success : function(data, status, xhr){
                   //show success message
                error: function(xhr, status, error){
                 //show error message

Example Project

Dependencies and Technologies Used:

  • jersey-core-server 2.22.1: Jersey core server implementation.
  • jersey-container-servlet 2.22.1: Jersey core Servlet 3.x implementation.
  • jersey-media-moxy 2.22.1: Jersey JSON entity providers support module based on EclipseLink MOXy.
  • jersey-test-framework-provider-jdk-http 2.22.1: Jersey Test Framework - JDK HTTP container.
  • JDK 1.8
  • Maven 3.0.4

Jxrs Put Ajax Select All Download
  • jaxrs-jquery-form-put
    • src
      • main
        • java
          • com
            • logicbig
              • example
                • api
          • webapp
        • test
          • java
            • com
              • logicbig
                • example

    Running the application:

    Run the embedded tomcat server: d:\examples\jaxrs-jquery-form-put>mvn clean install tomcat7:run-war -DskipTests

    Use the following link to submit the HTML form: http://localhost:8080/jaxrs-jquery-form-put/form.html

    On successful submission you will see the response at the bottom with new resource URI

    Now you can access the new resource at: http://localhost:8080/jaxrs-jquery-form-put/api/items/10

    Create multiple items from the the HTML form.

    To see all items use the resource link: http://localhost:8080/jaxrs-jquery-form-put/api/items

    See Also