Send array to Struts2 action with jQuery AJAX call -


so far, i've been able send simple string struts2 action class, via ajax call. time need same, string array, , i've changed code this:

1. ajax call:

var test = [1, 2, 3, 4, 5];  $.ajax({     method: "post",     url: "createexperiment4.action",     data: { test : test },     success:         function()         {             window.location = "loadexperiments.action";         } }); 

2. createexperiment4action.java:

private string[] test;  [...]  public void settest(string[] test) {     this.test = test; } 

however, data isn't arriving action calss. also, keep getting warning, of course must key problem:

warning: parameter [test[]] didn't match acceptedpattern pattern!

maybe kind of configuration issue?

jquery.ajax's default serialization arrays appends [] after name (eg test[]=1&test[]=2), while frameworks php recognizes format, struts doesn't. in order prevent behaviour add traditional: true, configuration ajax request, give test=1&test=2.

var test = [1, 2, 3, 4, 5]; $.ajax({     method: "post",     url: "createexperiment4.action",     data: { test : test },     traditional: true,     success:         function()         {             window.location = "loadexperiments.action";         } }); 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -