1

With several checkboxes checked I want to send array when I use $.ajax() but there is null pointer Exception with no parameter in controller.java I attached ajax part of javascript in jsp and part of controller.java

//view part

 var empno = $('input:checkbox[name="checkbox"]:checked');
       var i;
       var array = new Array();

       for(i=0; i<empno.length; i++){

            empnoyo = empno[i].getAttribute("id");//id='{EmpVO.EMPNO}';
            array.push(empnoyo[i]);

       } 

         alert('empnnoyo:'+empnoyo);
         $.ajaxSettings.traditional = true;

       $.ajax({
          url:"/delete",
          data: {array:array},
          dataType: 'text',
          processData: false,
          contentType: false,
          type: 'POST',
          success: function(result){
            if(result==1)  
              alert('delete complete');
              location.href='/index';

          }
      });
  }

//controller part
 @RequestMapping(value="/delete")
public String delete(int[] empno) throws Exception{

    int i=0;
    System.out.println("delete arr:"+empno[i]);
    for(i=0; i<empno.length; i++) {
       service.remove(empno[i]);    
    }   
  return "redirect:index";
}
1

1 Answer 1

1

Remove processData and contentType and change {array:array} to {empno:array}

The processData and contentType thing is only really useful for FormData and Binary types.

Your server-side code expects the parameter as empno not array

   $.ajax({
      url:"/delete",
      data: {empno:array},
      dataType: 'text',
      type: 'POST',
      success: function(result){
        if(result==1)  
          alert('delete complete');
          location.href='/index';

      }
  });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.