验证中...
助力高校计算机教育 —— 码云为老师推出免费高校版,高达 200 人的协作团队
JSON在不同系统交互时ajax调用存在跨域问题
原始数据 复制代码
package com.open.utils;
import java.io.IOException;
import java.util.LinkedHashMap;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
public class ResponseUtil {
public static void toWrite(Object obj,HttpServletResponse response){
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expires", 0); // Proxies.
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization");
response.setHeader("Access-Control-Allow-Credentials","true");
try {
response.setContentType("text/html;charset=utf-8");
JSONObject jsonNode = new JSONObject(new LinkedHashMap());
jsonNode.put("resultInfo", obj);
response.getWriter().write(jsonNode.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}

评论列表( 1 )

大秦 2018-06-14 18:16

有很多解决方案,你可以配置代理去请求

你可以在登录后,发表评论

10_float_left_people 10_float_left_close