欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ajax跨域问题

程序员文章站 2022-07-08 11:42:43
在java代码的方法里面增加响应头: @RequestMapping(value="getCode.html") @ResponseBody public List> getCode(ServletRequest request, ServletResponse ......

在java代码的方法里面增加响应头:

@RequestMapping(value="getCode.html")
 @ResponseBody
 public List<Map<Object,Object>> getCode(ServletRequest request, ServletResponse resp) throws IOException, ServletException{
  HttpServletResponse response = (HttpServletResponse) resp;
  response.setHeader("Access-Control-Allow-Origin", "*");
  response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");