If you need to enable CORS in tomcat ( or alternatively just serve your response in JSON-P format) you will need version 7.0.41 or greater.
Simply add the following in your web.xml file
<filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
This will ensure that the client browser honors the response that is returned from your app server.
You only need this if the client domain is different from the server which is returning your response.
Filed under: Web2.0 | Tagged: AJAX, CORS, Tomcat, web.xml | 2 Comments »