jsonp java 服务端代码
boolean jsonP = false; String cb = request.getParameter("callback"); if (cb != null) { jsonP = true; response.setContentType("text/javascript"); } else { response.setContentType("application/x-json"); } Writer out = response.getWriter(); if (jsonP) { out.write(cb + "("); } out.print(dataBlock.toJsonString()); if (jsonP) { out.write(");"); }
from:https://blog.csdn.net/michael10001/article/details/50386511
更多参考:
轻松搞定JSONP跨域请求:
https://www.cnblogs.com/xiaodongxiaodong/p/9391689.html