title: How to implement csv or excel file upload in spring boot and jsp using ajax?
body: <p>I am new to Spring Boot, and I am trying to implement a csv or excel file upload in my application. I have created a button in JSP page to upload file and store in my database. To upload file from backend, I have created API and after testing API, it is working fine. But the code written inside the script is not working properly. I have written the below code:
  Each time when I am trying to upload my file, I am getting 404 error. I do not know why. Any suggestions would be appreciated.</p>
  <pre><code>    function uploadpindata(){
              var delivercityid = document.getElementById('cityid').value;
              var formData = new FormData();
              var fileSelect = document.getElementById(&quot;file&quot;);
              if(fileSelect.files &amp;&amp; fileSelect.files.length == 1) {
                  var file = fileSelect.files[0];
                  formData.set(&quot;file&quot;,file,file.name);
                  console.log(&quot;Got the file&quot;);
              }else{
                  $(&quot;#file&quot;).focus();
                  return false;
              }
              var request = new XMLHttpRequest();
              try {
                  request.onreadystatechange=function() {
                      if(request.readyState==4) {
                          var v = JSON.parse(request.responseText);
                          if(v.status===&quot;OK&quot;) {
                              alert(&quot;New File Uploaded successfully&quot;);
                              location.reload();
                          }
                      }
                  }
                request.open('POST',&quot;../&lt;%=AkApiUrl.uploadpincodedata%&gt;/&quot;+delivercityid);
                request.send(formData);
                } catch(e) {
                    swal(&quot;Unable to connect to server&quot;,&quot;&quot;,&quot;error&quot;);
                }
  </code></pre>