Jetty Cross Origin Filter(码头跨源过滤器)
问题描述
我已经配置了 Jetty 的跨域过滤器,但我仍然收到以下错误.有谁知道出了什么问题以及如何解决?错误消息下方是我的覆盖描述符(即补充 web.xml)
I've configured Jetty's cross origin filter, but I continue to get the following error. Does anyone know what is wrong and how to fix it? Below the error message is my override descriptor (i.e. supplemental web.xml)
错误:
Origin http://localhost:8090 is not allowed by Access-Control-Allow-Origin.
覆盖描述符:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<filter-pattern>/*</filter-pattern>
</filter-mapping>
</web-app>
请求标头
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:Origin, Content-Type, Accept
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:8090
Referer:http://localhost:8090/home
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.942.0
响应标头
Allow:POST,GET,OPTIONS,HEAD
Content-Length:0
Date:Wed, 30 Nov 2011 02:13:21 GMT
Server:Jetty(7.5.4.v20111024)
推荐答案
Aloha,
我也为此奋斗了一段时间,发现最终节点需要是:
I fought this for awhile as well, and found that the final node needs to be:
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
不是
<filter-mapping>
<filter-name>cross-origin</filter-name>
<filter-pattern>/*</filter-pattern>
</filter-mapping>
这是我找到的对我有帮助的链接:wiki.eclipse.org/Jetty/Feature/Cross_Origin_Filter
Here is the link I found to help me: wiki.eclipse.org/Jetty/Feature/Cross_Origin_Filter
在我更新了 web.xml 文件并重新启动了码头服务器后,我能够使用 jQuery ajax 调用进行跨域请求.
After I updated my web.xml file and restarted the jetty server, I was able to make cross domain request using jQuery ajax calls.
罗伯
这篇关于码头跨源过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:码头跨源过滤器
基础教程推荐
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01