java 请求跨域问题解决方法实例详解
新建Util类,在Util中添加下面方法:
1
2
3
4
5
6
7
8
9
10
11
12
|
/* * response请求跨域公共设置 */ public static HttpServletResponse SetHttpServletResponse( HttpServletResponse response) { 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" ); return response; } |
在接口处调用此方法:
1
2
3
4
5
|
public String xxx(){ Util.SetHttpServletResponse(response); //解决跨域 ... return xxx; } |
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://blog.csdn.net/mr_ooo/article/details/70224724