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

 

posted @ 2019-12-05 13:43  SummerSoft  阅读(640)  评论(0编辑  收藏  举报