0

I want to insert data upload file/image into database using JSP/Servlet with AJAX , but its not working .. My codes are ..

HTML FORM :

<form id="formID">
  <input type="hidden" name="id" value="000">
  Username: <input type="text" name="uname" value="">
  File: <input name="filename" type="file" />
  <button type="submit" value="Submit"> Submit Data </button>
</form>

AJAX CODE IS :

    $('#formID').on('submit', function(event){
        event.preventDefault();
        var formData = new FormData($(this)[0]);
        $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "UsersController",
            data: formData,
            processData: false,
            contentType: false,
            cache: false,
            success: function (data) {
                alert(data);
            },
            error: function (e) {
                alert(e.responseText);
            }
        });
    });

no value are receiving in Servlet and its return a blank alert . Can anyone please suggest a better code for JSP file/image uploading.

Thanks to all .

RTR
  • 5
  • 6

1 Answers1

0

Refer this example

Servlet +Ajax upload file asynchronasly

http://hmkcode.com/java-servlet-jquery-file-upload/

Sibin Rasiya
  • 1,132
  • 1
  • 11
  • 15