Solution to the No ' access-control-allow-origin ' header problem when accessing the Tomcat Server Web service interface via Ajax

Source: Internet
Author: User
Tags tomcat server

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.