使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作

Send JSON object to Struts 2 action by using strut2 jquery plugin tags

我们可以通过 json 拦截器将 JSON 发送到 Struts2 动作。 http://tech.learnerandtutor.com/send-json-object-to-struts-2-action-by-jquery-ajax/.

处有很好的样本

json拦截器要求请求content typeapplication/jsonapplication/json-rpc这个可以在我们直接使用Ajax时设置如:

$.ajax({
    url: "writeJSON.action",
    data: data1,
    dataType: 'json',
    contentType: 'application/json',

但是我们正在使用 struts 2 jquery 插件标签(sj:asj:submit ...)来管理我们的 ajax 调用。

有什么方法可以用这些标签设置 contentType

我没有找到这个的标签属性。

如果没有实现,有没有其他方法可以设置。

您应该将 Content-type: application/json header 设置为 $.ajax().

使用的 xhr object
$.ajax({
    url: "writeJSON.action",
    data: data1,
    dataType: 'json',
    contentType: 'application/json',

插件正在使用$.ajaxSubmit(),这种提交应该被淘汰,因为它不适用于json数据。