我知道这种技术是 Cross Origin 或跨域或 CORS(跨域资源共享),我看过几个主题谈到它:
How to call a page from another domain to my domain using ajax/javascript
How does Access-Control-Allow-Origin header work?
https://www.html5rocks.com/en/tutorials/cors/
但我不知道如何配置我的网站以允许跨域查询。
信息:需要访问我的网站不使用浏览器扩展,因此我必须练习跨域。
1。如何配置Java-EE
标头?我的网站是JSF
,Spring
和Access-Control-Allow-Origin
。
2。我找到了两个解决方案,允许外部网站拥有我的网页内容:
<script>
(function (w,i,d,g,e,t,s)
w[d] = w[d]||[];
t= i.createElement(g);
t.async=1;
t.src=e;
s=i.getElementsByTagName(g)[0];
s.parentNode.insertBefore(t, s);
})(window, document,'_gscq','script','//widgets.getsitecontrol.com/42540/script.js');
</script>
吗?)实施例
XMLHttpRequest
B)第二种解决方案是外部网站使用AJAX
或my_page_1.html: // Page of my site
// Authorize sites to make a cross domain query
external_site_1.com
external_site_2.com
external_site_3.com
my_page_2.html: // Page of my site
// Authorize sites to make a cross domain query
external_site_1.com
my_page_3.html: // Page of my site
// Authorize sites to make a cross domain query
external_site_1.com
external_site_3.com
请求加载我的网站页面:
Embed an External Page Without an Iframe?
最佳解决方案是什么( A 或 B )?页面内容是否会以静态加载?
3。网站配置中是否有文件允许我授权或禁止网站(域)访问我网站的网页? Access-Control-Allow-Origin Multiple Origin Domains?
实施例
dataLayer.push({'event' : 'form_submitted'});
提前感谢您的回答。
答案 0 :(得分:0)
您可以使用不同的域定义多个过滤器:
<filter>
<filter-name>CorsFilter1</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>domain1</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter1</filter-name>
<url-pattern>/path1/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CorsFilter2</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>domain2, domain3</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter2</filter-name>
<url-pattern>/path2/*</url-pattern>
<url-pattern>/path3/*</url-pattern>
</filter-mapping>