如何在apache tomcat中启用CORS [英] How to enable CORS in apache tomcat

查看:455
本文介绍了如何在apache tomcat中启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一些跨域的Web服务。当我禁用chrome的web安全,它是工作正常。我希望它没有这样工作,所以我已经尝试添加cross-domain.xml和仍然没有工作。当我搜索更多,了解CORS启用在tomcat。



http://www.w3.org/wiki/CORS_Enabled






对于Apache
Apache可以配置为使用mod_headers公开此标头。默认情况下,这是在Apache中启用的,但是您可能希望通过运行以下命令确保其在您的部署中已启用:

  a2enmod headers 

要显示标题,您可以在,和, .htaccess文件。

 < IfModule mod_headers.c> 
标题集Access-Control-Allow-Origin*
< / IfModule>






任何人都可以让我知道在哪里添加TOMCAT中的配置和确切的文件。我使用的是eclipse的tomcat。



感谢任何帮助。

解决方案

Tomcat中的CORS支持通过过滤器提供。您需要将此过滤器添加到您的web.xml文件并配置它以满足您的要求。有关可用配置选项的完整详细信息,请参见 Tomcat文档。 / p>

I am trying to consume some web services which are cross domain. When I disable chrome's web-security it is working fine. I want it to work without this so I have tried adding cross-domain.xml and still it didnt work. When i searched more, came to know about CORS enabling in tomcat.

from http://www.w3.org/wiki/CORS_Enabled


For Apache Apache can be configured to expose this header using mod_headers. This is enabled by default in Apache, however you may want to ensure it's enabled in your deployment by running the following command:

a2enmod headers

To expose the header, you can add the following line inside , , and sections, or within an .htaccess file.

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>


Can anyone please let me know where to add these configurations in TOMCAT and in which files exactly. I am using tomcat from eclipse.

Appreciate any help.

解决方案

CORS support in Tomcat is provided via a filter. You need to add this filter to your web.xml file and configure it to match your requirements. Full details on the configuration options available can be found in the Tomcat Documentation.

这篇关于如何在apache tomcat中启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆