Cross-domain access solutions

When you send a request to the current server part in an external server or another server, such as Ajax request, is limited browser same-origin policy, No 'Access-Control-Allow-Origin' header is present on the requested resource 'solution is as follows:

@RequestMapping(value = "/query",method = RequestMethod.GET)
public Map<String,Object> queryRunoob(HttpServletResponse response){
    response.setHeader("Access-Control-Allow-Origin", "http://localhost:8080");
    response.setHeader("Access-Control-Allow-Methods", "GET,POST");
    Map<String,Object> modelMap = new HashMap<String,Object>();
    .
    .
    .
    return modelMap;
}

Is the red part ip and port to allow access, may be provided as *, which allows all requests.

Guess you like

Origin www.cnblogs.com/YeHuan/p/12120505.html