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

 

上一篇:棋盘覆盖


下一篇:jsonp跨域