今天在编码的时候遇到遇到一个奇特的问题,在前端客户段提交json数据到Struts2时,在通过request.getParameter()对相应的json数据进行获取竟然是null
前台jquery如下:
$.post("test.do", {"reportId":"2c90f1884cc110e6014cc117de000002","fileFormat":"Docx","reName":"text","columns":"名字;狀態","isIndent":"Y"} );
以上是最常见的一种普通json,單一的key-value形式,这种就能通过request.getParameter("name")获取对应的值
但是如果是一下这种情况的话就难说了
$.post("test.do", {"reportId":"2c90f1884cc110e6014cc117de000002","fileFormat":"Docx","reName":"text","columns":"名字;狀態","isIndent":"Y","conditionDTOs":[{"keyName":"nameLike","keyCode":"like","keyValue":"%会%"}]} );
public String exportReportByJson() throws IOException { HttpServletRequest request = ServletActionContext.getRequest(); String line =null; StringBuffer json = new StringBuffer(); BufferedReader reader = null; reader = request.getReader(); while((line = reader.readLine()) != null) { json.append(line); } reader.close(); System.out.println(json.toString()); return null; }
复杂的json提交给Struts2普通的request.getParameter()是获取不到的
原文地址:http://blog.csdn.net/qq183293/article/details/45103115