Home >Database >Mysql Tutorial >Java Web如何设置多个Access

Java Web如何设置多个Access

WBOY
WBOYOriginal
2016-06-07 15:36:391225browse

有没有办法让 Access-Control-Allow-Origin header允许设置 multiple cross-domains呢? 如果设置 response.addHeader("Access-Control-Allow-Origin","*"); 感觉这个接口太开放了,不太安全。 我想只设置自己指定的若干个域名或者端口可以调用接口。 想下面

有没有办法让Access-Control-Allow-Origin header允许设置multiple cross-domains呢?

如果设置 

response.addHeader("Access-Control-Allow-Origin","*");
感觉这个接口太开放了,不太安全。 我想只设置自己指定的若干个域名或者端口可以调用接口。

想下面这样:

Access-Control-Allow-Origin: http://www.domain1.com, http://domain2.com

 现在我通过这个方式,在filter里面设置头信息。

response.addHeader("Access-Control-Allow-Origin","http://www.domain1.com:9000");
response.addHeader("Access-Control-Allow-Origin","http://www.domain2.com:8080");

但是浏览器报这个错误。

The 'Access-Control-Allow-Origin' header contains multiple values 'http://www.liuxuewei.com:9000, http://www.liuxuewei.com:8080', but only one is allowed. Origin 'http://www.liuxuewei.com:9000' is therefore not allowed access.

Java Web如何设置多个Access



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn