Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CORS in apache tomcat [duplicate]

Tags:

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.

like image 711
Ravi Dasari Avatar asked Mar 20 '14 07:03

Ravi Dasari


People also ask

How to enable CORS in apache tomcat?

Tomcat Web Server Config To enable CORS support we have to use CORS Filter. If you want to enable CORS for all webapps, add the filter into $CATALINA_BASE/conf/web. xml. If you want to enable them only for the MOTECH application, add the filter into $CATALINA_BASE/webapps/motech-platform-server/WEB-INF/web.

How to resolve CORS issue in tomcat?

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.

What is Tomcat CORS filter?

CORS Filter Introduction. This filter is an implementation of W3C's CORS (Cross-Origin Resource Sharing) specification, which is a mechanism that enables cross-origin requests. The filter works by adding required Access-Control-* headers to HttpServletResponse object.


1 Answers

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.

like image 145
Mark Thomas Avatar answered Oct 02 '22 14:10

Mark Thomas