private void sendJSONP(HttpServletResponse resp,CharSequence json,String jsonp) { resp.setContentType(JSON_CONTENT_TYPE); PrintWriter writer = null; try { writer = resp.getWriter(); writer.write(jsonp + "(" + json.toString() + ")"); log.debug("response output:" + json); } catch (IOException e) { log.error("export JSON 出错:" + e.getMessage()); if (log.isDebugEnabled()) { log.debug("",e); } throw new RuntimeException(e.getMessage(),e); } finally { if (writer != null) { writer.flush(); writer.close(); } } }
调用方法
this.sendJSONP(resp,JsonUtils.Map2json(returnMap),request.getParameter("callback"));原文链接:https://www.f2er.com/json/289490.html