Pat*_*yer 9 ajax tomcat cors tomcat7
我正在尝试在$ 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
Date:Thu, 29 Jan 2015 15:19:00 GMT
Location:http://localhost:8080/crossDomain/
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.我有一种感觉,我没有以适当的方式发送请求,但实际上不知道.
如果您web.xml有其他具有调度程序详细信息的过滤器,例如
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
Run Code Online (Sandbox Code Playgroud)
然后 CORS Filter 没有对我起作用。
然而,下面的过滤器映射就成功了。
<filter-mapping>
<filter-name>CORS Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
<dispatcher>FORWARD</dispatcher>是魔法
希望这对你朋友有帮助!
| 归档时间: |
|
| 查看次数: |
3294 次 |
| 最近记录: |