protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 设置响应头数据 response.setHeader(null, "HTTP/1.1 200 OK"); response.setHeader("Server", "Apache-Coyote/1.1"); response.setHeader("Date", "Sun, 10 Jan 2016 04:09:02 GMT"); // 当有下面这一个头设置时,访问得不到想要的json数据,不设置就可以访问并得到json数据 // response.setHeader("Transfer-Encoding", "chunked"); response.setHeader("Content-Type", "application/json;charset=UTF-8"); // 本地的一个json数据文件 File file = new File("D:/Environments/test.json"); InputStream in = new FileInputStream(file); byte[] buffer = new byte[1024]; int num = 0; OutputStream out = response.getOutputStream(); while((num=in.read(buffer))!=-1){ out.write(buffer, 0, num); } if(in!=null){ in.close(); } }
在上述的响应头Transfer-Encoding设置了,为什么不能够得到json数据?未知
D:/Environments/test.json
{"rows":[{"id":"1","data":["0","1","工地监测_金石·星海湾·大门","工地","魏都区","是","2015-12-10 18:05:36","<a href=‘javascript:void(0)‘ onclick=editProject(‘1‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘1‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘1‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘1‘);>设施标准</a>"]},{"id":"2","data":["0","2","工地监测_金汇广场·大门","工地","魏都区","是","2015-12-11 11:05:52","<a href=‘javascript:void(0)‘ onclick=editProject(‘2‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘2‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘2‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘2‘);>设施标准</a>"]},{"id":"3","data":["0","3","工地监测_壹号城邦东门","工地","魏都区","是","2015-12-11 11:07:53","<a href=‘javascript:void(0)‘ onclick=editProject(‘3‘);>工程信息</a>/<a href=‘javascr ipt:void(0)‘ onclick=editMonitorType(‘3‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘3‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘3‘);>设施标准</a>"]},{"id":"4","data":["0","4","工地监测_许昌恒大绿洲三期","工地","魏都区","是","2015-12-11 11:08:40","<a href=‘javascript:void(0)‘ onclick=editProject(‘4‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘4‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘4‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘4‘);>设施标准</a>"]},{"id":"5","data":["0","5","工地监测_金石·星海湾·内部","工地","魏都区","是","2015-12-11 11:10:21","<a href=‘javascript:void(0)‘ onclick=editProject(‘5‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘5‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘5‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘5‘);>设施标准</a>" ]},{"id":"6","data":["0","6","工地监测_财富广场","工地","魏都区","是","2015-12-11 11:11:00","<a href=‘javascript:void(0)‘ onclick=editProject(‘6‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘6‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘6‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘6‘);>设施标准</a>"]},{"id":"7","data":["0","7","工地监测_金汇广场·内部","工地","魏都区","是","2015-12-11 11:12:32","<a href=‘javascript:void(0)‘ onclick=editProject(‘7‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘7‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘7‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘7‘);>设施标准</a>"]},{"id":"8","data":["0","8","工地监测_南关村安置小区项目","工地","魏都区","是","2015-12-11 11:13:29","<a href=‘javascript:void(0)‘ onclick=editProject(‘8‘);>工程信息</a>/<a href=‘javascript:void(0 )‘ onclick=editMonitorType(‘8‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘8‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘8‘);>设施标准</a>"]},{"id":"9","data":["0","9","工地监测_澜菲溪岸","工地","魏都区","是","2015-12-11 11:14:03","<a href=‘javascript:void(0)‘ onclick=editProject(‘9‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘9‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘9‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘9‘);>设施标准</a>"]},{"id":"10","data":["0","10","工地监测_壹号城邦西门","工地","魏都区","是","2015-12-11 11:15:36","<a href=‘javascript:void(0)‘ onclick=editProject(‘10‘);>工程信息</a>/<a href=‘javascript:void(0)‘ onclick=editMonitorType(‘10‘);>门限设置</a>/<a href=‘javascript:void(0)‘ onclick=editGkz(‘10‘);>关联国控站</a>/<a href=‘javascript:void(0)‘ onclick=editMeasure(‘10‘);>设施标准</a>"]}]}
时间: 2024-10-27 19:10:42