【发布时间】:2015-01-19 10:10:29
【问题描述】:
我有一个包含隐藏输入的 html 表单。我想用 json 字符串(可能是长字符串)填充这个输入,然后在我的控制器中通过 @RequestParam 获取它。这是我的 javascript 代码(注意表单是由页面上的某个事件生成的):
var filters = JSON.stringify("some data");
//I used console.log for print out the filters and this is ok.
$("body").append('<form target="_blank" id="excel" action="/company/excel" method="POST"></form>');
$('<input type="hidden" name="filter" value="'+filters+'" />').appendTo("#excel");
$("#excel").submit();
这是我的行动:
@RequestMapping(value = "company/excel", method = RequestMethod.POST)
public void companyExcelExport(@RequestParam String filter) throws IOException{
System.out.println(filter);
}
当动作执行时,netbeans 控制台中只打印“{”。有什么问题?
我使用了console.log(filters),它返回了我:
{"search":false,"nd":1421663503100,"rows":10,"page":1,"sidx":"","sord":"asc","pageGridColModelList":[{"name":"id","index":"id","width":150,"sortType":"integer","hidden":true,"hiddenlg":true,"stype":"text","searchoptions":{"stype":"integer","sopt":["eq","ne","lt","le","gt","ge","bw","bn","in","ni","ew","en","cn","nc"]}},{"name":"name","index":"name","width":250,"sortType":"string","hidden":false,"hiddenlg":false,"stype":"text","searchoptions":{"stype":"text","sopt":["eq","ne","lt","le","gt","ge","bw","bn","in","ni","ew","en","cn","nc"]}},{"name":"createAt","index":"createAt","width":420,"sortType":"date","hidden":false,"hiddenlg":false,"stype":"text","searchoptions":{"stype":"integer","sopt":["eq","ne","lt","le","gt","ge","bw","bn","in","ni","ew","en","cn","nc"]}}]}
【问题讨论】:
-
filters发帖的客户端内容是什么? -
它包含正确的 json 值。
-
你检查了吗?请张贴内容的前几个字符。
-
我会编辑帖子。
-
我认为问题出在字符串中的双引号 ;)
标签: java spring spring-mvc hidden-field