0

I have an array that gets populated and then as I send it my servlet receives it as null.

var allIcons = new Array();
$('.icon').each(function(index){
  allIcons.push($(this).find('.iconName').html());
});

That seems to be filling up the array with the appropriate fields

I am then passing it to my servlet using

$.ajax({
   "dataType" : 'json',
   "type": 'GET',
   "url" : 'update'
   "data" :{
      "allIcons" : allIcons
   }, "success": function(json){alert("alert");}});

My servlet is then attempting to read it but always gets back null

if(request.getParamtersValues("allIcons").length > 0) {/*do something*/}

request.getParamterValues() should return a String[]

In addition I know my servlet is able to receive data since this is in addition to some other code. Thanks -Tommy

3
  • 1
    do a request.getParameterNames() and see what you got there first. Commented Oct 3, 2012 at 16:36
  • sounds like js array allIcons don't have any data in it. Commented Oct 3, 2012 at 20:01
  • Well.... yes, the request.getParameterNames() returned me "allIcons[]" where I was looking for "allIcons" without the brackets. So, if you are looking for an array coming from JS to a servlet be sure to use the right parameters and put '[]' Commented Oct 4, 2012 at 14:43

2 Answers 2

1
$.ajax({
   dataType : 'json',
   type: 'GET',
   url : 'update'
   data :{
      "allIcons" : allIcons
   }, success: function(data){alert("alert");}});
Sign up to request clarification or add additional context in comments.

1 Comment

That works for the jquery/ajax side but on the servlet side I was having trouble finding the name of what was being passed. As I commented (with the answer) I needed the braces at the end.
0

The request.getParameterNames() returned me "allIcons[]" where I was looking for "allIcons" without the brackets. So, if you are looking for an array coming from JS to a servlet be sure to use the right parameters. Be sure to add your braces. "[]"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.