public static void write(HttpServletResponse response,String content) {
response.reset();
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-store");
response.setCharacterEncoding("UTF-8");
response.addHeader("Access-Control-Allow-Origin","*");//添加次行代码解决跨域问题
try {
PrintWriter pw=response.getWriter();
pw.write(content);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
如若不行的话请参考下面这篇文章
本人参考这篇文章解决的问题