title: Why the ajax response object: object from spring controller?
body: <p>There is an employee registration from. I have sent the value to controller by ajax calling. Controller has got the value ( I saw the value in debugging) . But when I alert the response in jquery:  </p>
  
  <pre><code>  success: function(response){
        // var obj = JSON.parse(response);
        var obj = jQuery.parseJSON(JSON.stringify(response));
        alert(response);
    },
  </code></pre>
  
  <p>it shows [object: object]
  But I want this type of response, like:
  <a href="https://i.stack.imgur.com/hNWTH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hNWTH.png" alt="this is an demo example"></a></p>
  
  <p>This is my JSP page:</p>
  
  <pre><code>    var company = [] ;
      var from = [] ;
      var to = [] ;
      var year =[];
      var organization =[];
      var topic =[];
      var duration =[];
  
  
  
      jQuery(document).ready(function($) { 
           var files; 
              var exp = $('input:radio[name=exp]:checked').val();
              var training = $('input:radio[name=training]:checked').val();
  
              $("#pexp").hide();
              $("#fieldexp").hide();
              $("#ptrain").hide();
              $("#fieldtrain").hide();
  
  
          $("#btnSubmit").click(function(){
  
              addEmployeeOnlineInformation();
               processFileUpload();
  
          });
  
       $("#image").on('change',prepareLoad);
  
  
  
      $('input[type=radio][name=exp]').change(function() {
          if (this.value == 'Yes') {
  
               $("#pexp").show();
  
               addExp();
          }
          else if (this.value == 'No') {
  
              $("#pexp").hide();
              $("#addmorefieldexp").empty();
  
          }
      });
  
      $('input[type=radio][name=train]').change(function() {
          if (this.value == 'Yes') {
  
               $("#ptrain").show();
  
               addTrain();
          }
          else if (this.value == 'No') {
  
              $("#ptrain").hide();
              $("#addmorefieldtrain").empty();
  
          }
      });
  
      });
  
  
  
      function addExp(){
  
             var scntDiv = $('#addmorefieldexp');
  
  
  
             $('#pexp').live('click', function() {
                            $( ' &lt;br&gt;&lt;br&gt;'
                              +'&lt;label for="inputPassword3" class="col-sm-2 control-label"&gt;Company Name&lt;/label&gt;'
                              +'&lt;div class="col-sm-2"&gt;'
                              +'&lt;input type="text" class="form-control" name="field_company[]"&gt;'
                              +'&lt;/div&gt;'
  
                              +'&lt;label for="inputPassword3" class="col-sm-1 control-label"&gt;From&lt;/label&gt;'
                              +'&lt;div class="col-sm-2"&gt;'
                              +'&lt;input type="text" class="form-control" name="field_from[]"&gt;'
                              +'&lt;/div&gt;'
  
                              +'&lt;label for="inputPassword3" class="col-sm-1 control-label"&gt;To&lt;/label&gt;'
                              +'&lt;div class="col-sm-2"&gt;'
                              +'&lt;input type="text" class="form-control" name="field_to[]"&gt;'
                              +'&lt;/div&gt;'
  
                              +'&lt;label for="inputPassword3" class="col-sm-1 control-label"&gt;Year&lt;/label&gt;'
                              +'&lt;div class="col-sm-1"&gt;'
                              +'&lt;input type="text" class="form-control" name="field_year[]"&gt;'
                              +'&lt;/div&gt;').appendTo(scntDiv);
  
  
                          return false;  
  
             });
  
  
      }
  
      function addTrain(){
  
         var scntDiv = $('#addmorefieldtrain');
  
  
  
          $('#ptrain').live('click', function() {
                         $(        '&lt;div class="form-group text-center" id="fieldtrain"&gt;'
                                  +'&lt;label for="inputPassword3" class="col-sm-2 control-label"&gt;Organization&lt;/label&gt;'
                                  +'&lt;div class="col-sm-2"&gt;'
                                  +'&lt;input type="text" class="form-control" name="field_organization[]"&gt;'
                                  +'&lt;/div&gt;'
  
                                  +'&lt;label for="inputPassword3" class="col-sm-2 control-label"&gt;Topic&lt;/label&gt;'
                                  +'&lt;div class="col-sm-2"&gt;'
                                  +'&lt;input type="text" class="form-control" name="field_topic[]"&gt;'
                                  +'&lt;/div&gt;'
  
                                  +'&lt;label for="inputPassword3" class="col-sm-2 control-label"&gt;Duration&lt;/label&gt;'
                                  +'&lt;div class="col-sm-2"&gt;'
                                  +'&lt;input type="text" class="form-control" name="field_duration[]"&gt;'
                                  +'&lt;/div&gt;'
                                  +'&lt;/div&gt;').appendTo(scntDiv);
  
  
                       return false;  
  
          });
  
  
   }
  
      function array(){
  
  
  
          var inps = document.getElementsByName('field_company[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              company.push(inp.value);
      }
          var inps = document.getElementsByName('field_from[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              from.push(inp.value);
      }
          var inps = document.getElementsByName('field_to[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              to.push(inp.value);
      }
          var inps = document.getElementsByName('field_year[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              year.push(inp.value);
      }
          var inps = document.getElementsByName('field_organization[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              organization.push(inp.value);
      }
          var inps = document.getElementsByName('field_topic[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              topic.push(inp.value);
      }
          var inps = document.getElementsByName('field_duration[]');
          for (var i = 0; i &lt;inps.length; i++) {
          var inp=inps[i];
              duration.push(inp.value);
      }
      }
  
  
  
      function addEmployeeOnlineInformation(){
  
  
           array();
           var gender = $('#gender').val();
           var blood = $('#blood').val();
  
  
          $.ajax({
              type: "post",
              url: "http://localhost:8080/EmployeeOnlineRegistrationForm/employee",
              cache: false,
  
  
             data:'name=' + $("#name").val() 
                 +"&amp;fname=" + $("#fname").val() 
                 +"&amp;mname=" + $("#mname").val() 
                 +"&amp;nid=" + $("#nid").val() 
                 +"&amp;age=" + $("#age").val()
                 +"&amp;blood=" + blood
                 +"&amp;gender=" + gender 
                 +"&amp;caddress=" + $("#caddress").val() 
                 +"&amp;paddress=" + $("#paddress").val()
                 +"&amp;paddress=" + $("#paddress").val()
                 +"&amp;pdegree=" + $("#pdegree").val()
                 +"&amp;puniversity=" + $("#puniversity").val()
                 +"&amp;pyear="+ $("#pyear").val()
                 +"&amp;presult=" + $("#presult").val()
                 +"&amp;mdegree=" + $("#mdegree").val()
                 +"&amp;muniversity=" + $("#muniversity").val()
                 +"&amp;mresult=" + $("#mresult").val()
                 +"&amp;myear=" + $("#myear").val()
                 +"&amp;bdegree=" + $("#bdegree").val()
                 +"&amp;buniversity=" + $("#buniversity").val()
                 +"&amp;bresult=" + $("#bresult").val()
                 +"&amp;byear=" + $("#byear").val()
                 +"&amp;hdegree=" + $("#hdegree").val()
                 +"&amp;college=" + $("#college").val()
                 +"&amp;hresult=" + $("#hresult").val()
                 +"&amp;hyear=" + $("#hyear").val()
                 +"&amp;sdegree=" + $("#sdegree").val()
                 +"&amp;school=" + $("#school").val()
                 +"&amp;sresult=" + $("#sresult").val()
                 +"&amp;syear=" + $("#syear").val()
                 +"&amp;date=" + $("#date").val()
                 +"&amp;department=" + $("#department").val()
                 +"&amp;location=" + $("#location").val()
                 +"&amp;company=" + company
                 +"&amp;from=" + from
                 +"&amp;to=" + to
                 +"&amp;year=" + year
                 +"&amp;organization=" + organization
                 +"&amp;topic=" + topic
                 +"&amp;duration=" + duration,
  
              success: function(response){
  
                 // var obj = JSON.parse(response);
                  var obj = jQuery.parseJSON(JSON.stringify(response));
                  alert(obj);
  
              },
  
              error: function(){                      
                  alert('Error while request..');
              }
          });
  
      }
  
      function prepareLoad(event)
      {
          files=event.target.files;
      }
      function processFileUpload()
      {
          var oMyForm = new FormData();
          oMyForm.append("file", files[0]);
          $
              .ajax({dataType : 'text',
                  url : "http://localhost:8080/EmployeeOnlineRegistrationForm/uploadMyFile",
                  data : oMyForm,
                  type : "POST",
                  enctype: 'multipart/form-data',
                  processData: false,
                  contentType:false,
                  success : function(result) {
                      alert(result);
                  },
                  error : function(result){
                      alert('error'+result);
                  }
              });
      }
  </code></pre>
  
  <p>This is my Controller:</p>
  
  <pre><code>@Controller
  
  public class EmployeeRegistrationController {
  
      @RequestMapping(value="/employee",method = RequestMethod.POST)
       public @ResponseBody
       EmployeeOnlineRegistrationForm add(HttpServletRequest request, HttpServletResponse response)
         throws Exception {
          EmployeeOnlineRegistrationForm employeeregistration = new EmployeeOnlineRegistrationForm();
  
       String name = request.getParameter("name");
       String fname = request.getParameter("fname");
       String mname = request.getParameter("mname");
       String nid = request.getParameter("nid");
       String age = request.getParameter("age");
       String blood = request.getParameter("blood");
       String gender = request.getParameter("gender");
       String caddress = request.getParameter("caddress");
       String paddress = request.getParameter("paddress");
       String pdegree = request.getParameter("pdegree");
       String puniversity = request.getParameter("puniversity");
       String pyear = request.getParameter("pyear");
       String presult = request.getParameter("presult");
       String mdegree = request.getParameter("mdegree");
       String muniversity = request.getParameter("muniversity");
       String myear = request.getParameter("myear");
       String mresult = request.getParameter("mresult");
       String bdegree = request.getParameter("bdegree");
       String buniversity = request.getParameter("buniversity");
       String byear = request.getParameter("byear");
       String bresult = request.getParameter("bresult");
       String hdegree = request.getParameter("hdegree");
       String college = request.getParameter("college");
       String hyear = request.getParameter("hyear");
       String hresult = request.getParameter("hresult");
       String sdegree = request.getParameter("sdegree");
       String school = request.getParameter("school");
       String syear = request.getParameter("syear");
       String sresult = request.getParameter("sresult");
       String date = request.getParameter("date"); 
       String location = request.getParameter("location");
       String department =request.getParameter("department");
       String[] company =request.getParameter("company").split(",");
       String[] from =request.getParameter("from").split(",");
       String[] to =request.getParameter("to").split(",");
       String[] year =request.getParameter("year").split(",");
       String[] organization =request.getParameter("organization").split(",");
       String[] topic =request.getParameter("topic").split(",");
       String[] duration =request.getParameter("duration").split(","); 
  
       employeeregistration.setName(name);
       employeeregistration.setFname(fname);
       employeeregistration.setMname(mname);
       employeeregistration.setNid(nid);
       employeeregistration.setAge(age);
       employeeregistration.setBlood(blood);
       employeeregistration.setGender(gender);
       employeeregistration.setCaddress(caddress);
       employeeregistration.setPaddress(paddress);
       employeeregistration.setPdegree(pdegree);
       employeeregistration.setPuniversity(puniversity);
       employeeregistration.setPyear(pyear);
       employeeregistration.setPresult(presult);
       employeeregistration.setMdegree(mdegree);
       employeeregistration.setMuniversity(muniversity);
       employeeregistration.setMyear(myear);
       employeeregistration.setMresult(mresult);
       employeeregistration.setBdegree(bdegree);
       employeeregistration.setBuniversity(buniversity);
       employeeregistration.setByear(byear);
       employeeregistration.setBresult(bresult);
       employeeregistration.setHdegree(hdegree);
       employeeregistration.setCollege(college);
       employeeregistration.setHyear(hyear);
       employeeregistration.setHresult(hresult);
       employeeregistration.setSdegree(sdegree);
       employeeregistration.setSchool(school);
       employeeregistration.setSyear(syear);
       employeeregistration.setSresult(sresult);
       employeeregistration.setDate(date);
       employeeregistration.setDepartment(department);
       employeeregistration.setLocation(location);
       employeeregistration.setCompany(company);
       employeeregistration.setFrom(from);
       employeeregistration.setTo(to);
       employeeregistration.setYear(year);
       employeeregistration.setOrganization(organization);
       employeeregistration.setTopic(topic);
       employeeregistration.setDuration(duration);
  
       System.out.println(" name "+name+" fname "+fname+" mname "+mname+" blood "+blood+" gender "+ gender+" caddress "+caddress+" paddress "+paddress
            +" pyear "+pyear+" pdegree "+pdegree+" puniversity "+puniversity+" presult "+presult
            +" myear "+myear+" mdegree "+mdegree+"  muniversity "+muniversity+" mresult "+mresult
            +" byear "+byear+" bdegree "+bdegree+" buniversity "+buniversity+" bresult "+bresult
            +" hyear "+hyear+" hdegree "+hdegree+" college "+college+" hresult "+hresult
            +" syear "+syear+" sdegree "+sdegree+" school "+school+" sresult "+sresult
            +" date "+date+" location "+location+" department "+department);
  
        return employeeregistration;
       }
  
  
          @RequestMapping(value = "/welcome",method = RequestMethod.GET)
          public String index(ModelMap model){
              model.addAttribute("message", "Spring MVC XML Config Example");
              return "index";
          }
  
          @RequestMapping(value = "/uploadMyFile", method = RequestMethod.POST)
          @ResponseBody
          public String handleFileUpload(MultipartHttpServletRequest request)
                  throws Exception {
              Iterator&lt;String&gt; itrator = request.getFileNames();
              MultipartFile multiFile = request.getFile(itrator.next());
              try {
  
                  String fileName=multiFile.getOriginalFilename();
                  //String path=request.getSession().getServletContext().getRealPath("/");
                  //System.out.println(path);
                  //making directories for our required path.
                  byte[] bytes = multiFile.getBytes();
                  //File directory=    new File(path+ "/image");
                  File directory=    new File("/E:/Java_Project/EmployeeOnlineRegistrationForm/src/main/webapp/resources/image");
                  if(!directory.exists())
                      directory.mkdirs();
                  // saving the file
                  File file=new File(directory.getAbsolutePath()+System.getProperty("file.separator")+multiFile.getOriginalFilename());
                  BufferedOutputStream stream = new BufferedOutputStream(
                          new FileOutputStream(file));
                  stream.write(bytes);
                  stream.close();
              } catch (Exception e) {
                  e.printStackTrace();
                  throw new Exception("Error while loading the file");
              }
  
  
              return "File Uploaded Successfully";
          }
  </code></pre>
  
  <p>How Can I get this response from controller?</p>