Problem description
When accessing the JSON Web service interface in the Web server (Tomcat7.0.42) through Ajax, the following cross-domain issues are reported:
XMLHttpRequest cannot load http://localhost:8080/get-employees-by-name/name/admin. No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' http://localhost:63342 ' is therefore not allowed access.
Solutions
1. Download the Cors-filter-<version>.jar and Java-property-utils-<version>.jar two jar files and place them under the Classpath path of the Web server. For example, Tomcat Lib.
Cors-filter-2.4.jar Java-property-utils-1.9.1.jar
2. Add corsfilter filter in Web. xml
<Filter> <Filter-name>Corsfilter</Filter-name> <Filter-class>Com.thetransactioncompany.cors.CORSFilter</Filter-class></Filter><filter-mapping> <Filter-name>Corsfilter</Filter-name> <Url-pattern>/*</Url-pattern></filter-mapping><Filter>
3. Restart the Web server.
Resources
1, Http://stackoverflow.com/questions/17267023/tomcat-7-cors-filter
2, http://software.dzhuvinov.com/cors-filter-installation.html
Solution to the No ' access-control-allow-origin ' header problem when accessing the Tomcat Server Web service interface via Ajax