If you have Apache Tomcat there are two
choices: If you intend to use CORS with a single web application
put the JAR file in
To make CORS available globally, to all web applications, place the JAR in
Alternatively, if you use Maven to build your project WAR file,
add the following dependency to your
<dependency> <groupId>com.thetransactioncompany</groupId> <artifactId>cors-filter</artifactId> <version>[ version ]</version> </dependency>
where version should be the latest stable release of the CORS Filter.
The XML declaration to load the CORS filter:
<filter> <filter-name>CORS</filter-name> <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class> </filter>
To use a variant of the CORS Filter that can automatically detect changes to the configuration file and reconfigure itself use the following declaration instead:
<filter> <filter-name>CORS</filter-name> <filter-class>com.thetransactioncompany.cors.autoreconf.AutoReconfigurableCORSFilter</filter-class> </filter>
Then declare a filter mapping to tell the web server which servlets or URLs should be cross-domain-request enabled.
Example of applying the CORS filter to a single servlet:
<filter-mapping> <filter-name>CORS</filter-name> <servlet-name>MyServlet</servlet-name> </filter-mapping>
And how to apply the CORS filter to all web app URLs:
<filter-mapping> <filter-name>CORS</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Have a look at the
of the demo CORS application included with the download package to see
a complete CORS filter declaration and mapping example.
Finally, remember to restart your web server for the installation to take effect.
If you want to modify the default CORS Filter behaviour, proceed to the configuration instructions.