Struts2 jQuery DataTable 1.10 Mutidimensional Http

2019-01-15 21:02发布

I have a Struts 2 application that was using DataTables 1.9. I am now trying to convert it over to DataTables 1.10 which changed the way it sends the HTTP Parameters to the server. I am now trying to deal with a HTTP Parameter that looks like this:

columns[1][data]

I have a List in my struts action called "columns" which contains an object with a "data" property. Nothing gets pushing into the columns list when the action fires. I know that normally I would send a parameter like this using:

columns[1].data

I dug into the DataTables code and found out that it is using the jQuery.param to serialize the JS object created by DataTables. I have tried to set the "traditional" parameter on the ajax request to true, but then I get [object+Object] for the parameter value.

Can someone please tell me if there is a way to do one of the following:

  • Get Struts2 to deal with this parameter notation
  • Change the way jQuery serializes these parameter names

There is an option in DataTables to revert back to the old parameters it sent, but it seems like this may not be around forever and I would prefer to get it working with the new parameter structure.

1条回答
爷的心禁止访问
2楼-- · 2019-01-15 21:16

Parameters in following format columns[1]['data'] (note the ' around data) would actually work with Struts2. So you can try to tweak serialization process to add extra single quotes to parameters.

BUT it seems that you can send JSON string from DataTables, which is a better way of doing things rather than messing with parameter serialization. And there is struts2-json-plugin which can populate action variables from the JSON string.

查看更多
登录 后发表回答