小编Pat*_*yer的帖子

CORS过滤器Tomcat 7无效

我正在尝试在$ CATALINA_BASE/conf/web.xml文件中实现基本的CORS过滤器.这是我的过滤器:

<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>
Run Code Online (Sandbox Code Playgroud)

我已经确认我肯定在运行受支持的Tomcat版本:

Server version: Apache Tomcat/7.0.56
Server built:   Sep 26 2014 12:08:24
Server number:  7.0.56.0
Run Code Online (Sandbox Code Playgroud)

这是我的AJAX请求:

function MethodOne() {
$.ajax({
    type: "GET",
    url: "http://localhost:8080/crossDomain",
    crossDomain: true,
    success: function(response) {
        $('#result').html(response);
    }   
});
}
Run Code Online (Sandbox Code Playgroud)

我的请求/响应标头:

Remote Address:[::1]:8080
Request URL:http://localhost:8080/crossDomain
Request Method:GET
Status Code:302 Found
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:3000
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36    (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
Response Headersview source …
Run Code Online (Sandbox Code Playgroud)

ajax tomcat cors tomcat7

9
推荐指数
1
解决办法
3294
查看次数

标签 统计

ajax ×1

cors ×1

tomcat ×1

tomcat7 ×1